Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page Freezing

Status
Not open for further replies.

androidx

Programmer
Jun 13, 2002
5
CA
I have this script to allow a user to download a file. It is referenced from a form on an asp page.
when you click the download button, and save the file, the web page freezes up and you are unable to click on any links or use the back button on your browser. When you refresh, the page works fine.

<%@Language=&quot;VBScript&quot;%>
<%Option Explicit%>
<%Response.Buffer = True%>


<%
On Error Resume Next
Dim strPath
strPath = CStr(Request.QueryString(&quot;file&quot;))
'-- do some basic error checking for the QueryString
If strPath = &quot;&quot; Then
Response.Clear
Response.Write(&quot;No file specified.&quot;)
Response.End
ElseIf InStr(strPath, &quot;..&quot;) > 0 Then
Response.Clear
Response.Write(&quot;Illegal folder location.&quot;)
Response.End
ElseIf Len(strPath) > 1024 Then
Response.Clear
Response.Write(&quot;Folder path too long.&quot;)
Response.End
Else
Call DownloadFile(strPath)
End If

Private Sub DownloadFile(file)
'--declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
'-- set absolute file location
strAbsFile = Server.MapPath(file)
'-- create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

'-- check to see if the file exists
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
'-- first clear the response, and then set the appropriate headers
Response.Clear
'-- the filename you give it will be the one that is shown
' to the users by default when they save
Response.AddHeader &quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; & objFile.Name
Response.AddHeader &quot;Content-Length&quot;, objFile.Size
Response.ContentType = &quot;application/octet-stream&quot;
Set objStream = Server.CreateObject(&quot;ADODB.Stream&quot;)
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = &quot;UTF-8&quot;
'-- load into the stream the file
objStream.LoadFromFile(strAbsFile)
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream = Nothing
Set objFile = Nothing
Else 'objFSO.FileExists(strAbsFile)
Response.Clear
Response.Write(&quot;No such file exists.&quot;)
End If
Set objFSO = Nothing
End Sub


%>

 
try forum333

_____________________________________________________________________
Please help! I'm falling asleep over here!
onpnt2.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top