Hi everybody...
Here's a little background on what I'm doing so you can understand where I'm trying to go with this. I have a page that is doing a couple of things:
1. Create a text file that will be read by a crystal report.
2. Once the file has been created, I call a sub that does a window.open "crystalpage.asp","_self" to open the page that holds the crystal report
3. Also in that sub, I use window.open "StartDownload.asp", "_blank" to open a new window that will force the user to download the text file that was created(rather than displaying it to them in the browser and making them click file-->save as)
All 3 steps are working great but my question is on the StartDownload.asp page (step 3). How do I close this window after the file has been downloaded?
Below is my code for StartDownload.asp:
<%
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))
Case ".txt"
ContentType = "text/plain"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing%>
I've also written the code that I wanted to display in the pop-window while the file was downloading:
<HTML>
<HEAD>
</HEAD>
<BODY onload=closewindow()>
<P align=center><font color=red size=3>This window should close automatically<BR>
after the file has been downloaded.<BR>
If it does not, please click the button below.<br></font>
<input type=button onclick=closewindow() value=Close name=button1 id=button1>
<SCRIPT language=vbscript>
sub closewindow()
window.close
end sub
</SCRIPT>
</BODY>
</HTML>
I thought I could put this after the line that says
Set objStream = Nothing%>
and then do another response.flush, but it justs adds all of the html to the text file and does not display it in the browser.
Any help with this would be great...
Thanks in advance,
mwa
Here's a little background on what I'm doing so you can understand where I'm trying to go with this. I have a page that is doing a couple of things:
1. Create a text file that will be read by a crystal report.
2. Once the file has been created, I call a sub that does a window.open "crystalpage.asp","_self" to open the page that holds the crystal report
3. Also in that sub, I use window.open "StartDownload.asp", "_blank" to open a new window that will force the user to download the text file that was created(rather than displaying it to them in the browser and making them click file-->save as)
All 3 steps are working great but my question is on the StartDownload.asp page (step 3). How do I close this window after the file has been downloaded?
Below is my code for StartDownload.asp:
<%
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))
Case ".txt"
ContentType = "text/plain"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing%>
I've also written the code that I wanted to display in the pop-window while the file was downloading:
<HTML>
<HEAD>
</HEAD>
<BODY onload=closewindow()>
<P align=center><font color=red size=3>This window should close automatically<BR>
after the file has been downloaded.<BR>
If it does not, please click the button below.<br></font>
<input type=button onclick=closewindow() value=Close name=button1 id=button1>
<SCRIPT language=vbscript>
sub closewindow()
window.close
end sub
</SCRIPT>
</BODY>
</HTML>
I thought I could put this after the line that says
Set objStream = Nothing%>
and then do another response.flush, but it justs adds all of the html to the text file and does not display it in the browser.
Any help with this would be great...
Thanks in advance,
mwa