I have a download function that I use to initiate the open/save dialogue. While it does what it is supposed to, the method of using it is to put the function call in a seperate page.
The issue I am having is, when I try to use some javascript to close the popup window, the code for the window closing get added to the file on download (txt files). If I take out the javascript nothing extra gets added to the file, but the popped up window also does not close.
Please see this link to see what I mean:
http://www.getmysupport.com/filemanager/ If you click the floppy disk icon and save or open the file, you will see the javascript in the text file.
The function is:
Function DownloadFile( strFile, strDownloadFilename )
Dim strFilename,objStream,objF
ilesystem,
objFilestr
eam
Dim intFileLength
strFilename = strFile
Response.Buffer = True
Response.Clear
Set objStream = Server.CreateObject("ADODB
.Stream")
objStream.Open
objStream.Type = 1
Set objFilesystem = Server.CreateObject("Scrip
ting.FileS
ystemObjec
t")
if not objFilesystem.FileExists(s
trFilename
) then
Response.Write("<h1>Error<
/h1>: " & strFilename & " does not exist<p>")
Response.End
end if
Set objFilestream = objFilesystem.GetFile( strFilename )
intFilelength = objFilestream.size
objStream.LoadFromFile( strFilename )
if err then
Response.Write("<h1>Error:
</h1>" & err.Description & "<p>")
Response.End
end if
if Len( Trim(strDownloadFilename) ) > 0 then
strDownloadFilename = Trim( strDownloadFilename )
else
strDownloadFilename = objFilestream.name
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & strDownloadFilename
Response.AddHeader "Content-Length", intFilelength
Response.Charset = "UTF-8"
for i = 0 to objStream.size
i = i + 128000
Response.BinaryWrite(objSt
ream.Read(
128000))
Response.Flush
next
Set objFilestream = Nothing
End Function
and the code for the download.asp page is:
strPath = sPath & uPath(0,0) & "\" & fDown(3,0) 'full path to the file, and the filename
Call DownloadFile(strPath,fDown
(3,0))
closeWindow()'to close the popped up window