G
Guest
I am wanting to allow a client to download a file from a web server and save it on their local PC. The only way that I have found to do this is to use HTTP headers. I am using the code shown below (which I have copied with some variable name changes) from a book on ASP.NET programming. This code sits in the Page_Load event of a file called 'Download.aspx'. In order to send a file to the client, this page is called from another page (using Response.Redirect), passing it the full location of the file to be sent to the client. Everything works correctly except that the default file name that appears in the SaveAs dialog box on the client is always 'Download.aspx" rather than the name of the actual file. This happens despite the use of the "Content-Disposition attachment filename=..." header, which, according to the comment should set the default file name
Can anyone see what the problem is or suggest an alternative way of doing this? (I am using IE 6 as a browser.
Thanks
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
'Put user code to initialize the page her
Dim sFilePath As Strin
Dim oFile As IO.FileInf
sFilePath = Request.QueryString.Item("FilePath"
oFile = New System.IO.FileInfo(sFilePath
' Clear the current output content from the buffe
Response.Clear(
' Specify that the response is a stream that cannot be read by the client and must be downloade
Response.ContentType = "application/octet-stream
' Add the header that specifies the default filename for the Download/SaveAs dialo
Response.AddHeader("Content-Disposition", "attachment filename=" & oFile.Name
' Add the header that specifies the file size, so that the browser can show the download progres
Response.AddHeader("Content-Length", oFile.Length.ToString()
' Send the file stream to the clien
Response.WriteFile(oFile.FullName
' Stop the execution of this pag
Response.End(
End Su
Can anyone see what the problem is or suggest an alternative way of doing this? (I am using IE 6 as a browser.
Thanks
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
'Put user code to initialize the page her
Dim sFilePath As Strin
Dim oFile As IO.FileInf
sFilePath = Request.QueryString.Item("FilePath"
oFile = New System.IO.FileInfo(sFilePath
' Clear the current output content from the buffe
Response.Clear(
' Specify that the response is a stream that cannot be read by the client and must be downloade
Response.ContentType = "application/octet-stream
' Add the header that specifies the default filename for the Download/SaveAs dialo
Response.AddHeader("Content-Disposition", "attachment filename=" & oFile.Name
' Add the header that specifies the file size, so that the browser can show the download progres
Response.AddHeader("Content-Length", oFile.Length.ToString()
' Send the file stream to the clien
Response.WriteFile(oFile.FullName
' Stop the execution of this pag
Response.End(
End Su