force download 
Author Message
 force download

Hi, everyone:

I''m trying to open a download dialog box on the browser.
The folloiwng should force the specific file extention (.pdf) to be downloaded instead of opening.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<%
 Response.Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
strFilePath = Request.QueryString("File")
strFileSize = Request.QueryString("Size")
strFileName = Request.QueryString("Name")
Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = lcase(Right(strFileName, 4))
    Select Case strFileType
        Case ".pdf"
   ContentType = "text/pdf"
    End Select
 Response.AddHeader "Content-Disposition", "attachment; filename=000" & strFileName
 Response.AddHeader "Content-Length", strFileSize
 Response.Charset = "UTF-8"
 Response.ContentType = ContentType
 Response.BinaryWrite objStream.Read
 Response.Flush
objStream.Close
Set objStream = Nothing
%>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

However, other files (.asp, .htm, txt & etc.) on the current folder are also displayed from the following codes.
Does anyone know how to fix this problem?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%
  Dim strThisPage
 strThisPage = Request.ServerVariables("SCRIPT_NAME")
 strThisPage = Right(strThisPage, Len(strThisPage) - 1)

 FILE_FOLDER = StripFileName(Request.ServerVariables("PATH_TRANSLATED"))
%>
<HTML>
<HEAD>
 <TITLE>File Download List For</TITLE><%= Date() %>
 <STYLE TYPE="TEXT/css">
 .TabHeader { Font-Family: Arial; Font-Weight; Bold; Font-Size: 16px; Background: Silver }
 .DataCol { Font-Family: Verdana; Font-Size: 12px }
 </STYLE>
 <SCRIPT>
  function msg() {
   self.status = ''File Downloads For <%= Date() %>'';
   return true
  }
 </SCRIPT>
</HEAD>

<BODY onLoad="msg()">
<TABLE BORDER=1 ID=tblFileData BACKGROUND="">
 <TR>
  <TD CLASS=TabHeader>File Name</TD>
  <TD CLASS=TabHeader>File Type</TD>
  <TD CLASS=TabHeader>File Size</TD>
 </TR>
<%  
 GetAllFiles
%>

</TABLE>
</BODY>
</HTML>
<%  

Sub GetAllFiles()
 Dim oFS, oFolder, oFile
 Set oFS = Server.CreateObject("Scripting.FileSystemObject")

 Set oFolder = oFS.getFolder(FILE_FOLDER)

 Dim intCounter
 Dim FileArray()

 intCounter = 0
 ReDim Preserve FileArray(oFolder.Files.Count, 5)

 For Each oFile in oFolder.Files
  strFileName = oFile.Name
  strFileType = oFile.Type
  strFileSize = oFile.Size
  strFilePath = oFile.Path  

  FileArray(intCounter, 0) = strFileName
  FileArray(intCounter, 1) = "<A HREF=" & Chr(34) & "ForceDownload.asp?File=" _
   & strFilePath & "&Name=" & strFileName & "&Size=" & strFileSize & Chr(34) _
   & " onMouseOver=" & Chr(34) & "self.status=''" & strFileName & "''; return true;" & Chr(34) _
   & " onMouseOut=" & Chr(34) & "self.status=''''; return true;" & Chr(34) & ">" & strFileName & "</A>"
  FileArray(intCounter, 2) = strFileType
  FileArray(intCounter, 3) = strFileSize

  intCounter = (intCounter + 1)
 Next

 EchoB("<B>" & oFolder.Files.Count & " Files Available</B>")

 intRows = uBound(FileArray, 1)
 intCols = uBound(FileArray, 2)

 For x = 0 To intRows -1
  Echo("<TR>")
  For z = 0 To intCols
   If z > 0  Then
    BuildTableCol(FileArray(x, z))
   End IF
  Next
  Echo("</TR>")
 Next

 Cleanup oFile
 Cleanup oFolder
 Cleanup oFS
End Sub

Function Echo(str)
 Echo = Response.Write(str & vbCrLf)
End Function

Function EchoB(str)
 EchoB = Response.Write(str & "<BR>" & vbCrLf)
End Function

Sub Cleanup(obj)
 IF isObject(obj) Then
  Set obj = Nothing
 End IF
End Sub

Function StripFileName(strFile)
 StripFileName = Left(strFile, inStrRev(strFile, "\"))
End Function

Sub BuildTableCol(strData)
 Echo("<TD CLASS=DataCol>" & strData & "</TD>")
End Sub

Sub BuildTableRow(arrData)
 Dim intCols
 intCols = uBound(arrData)
 For y = 0 To intCols
  Echo("<TD CLASS=DataCol>" & arrData(y) & "</TD>")
 Next
End Sub

%>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-----------------------------
This message is posted by http://www.*-*-*.com/



Sat, 17 Jul 2004 09:31:44 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. How to force download?

2. Forced download

3. Force download

4. Force download of a .txt file

5. Force download of ALL fonts in MS-Win?

6. forcing download

7. Force Download

8. Force Download disables Links in Frames

9. Howto force Download instead of Open .doc?

10. Forcing download of email

11. How to force download dialogBox opening when clicking on a link?

12. how can i force downloading instead of viewing the file ?

 

 
Powered by phpBB® Forum Software