Re: Enabling a Client to Download a File
From: Martin Marinov (memmarinov_at_mecrossroad.bg)
Date: 06/03/04
- Next message: Vinodh Kumar[MS MVP]: "RE: Include asp code in aspx file"
- Previous message: Steve C. Orr [MVP, MCSD]: "Re: Include asp code in aspx file"
- In reply to: Sleepy: "Enabling a Client to Download a File"
- Next in thread: Sleepy: "Re: Enabling a Client to Download a File"
- Reply: Sleepy: "Re: Enabling a Client to Download a File"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 3 Jun 2004 09:25:59 +0300
It must be somthing with the strings in the header
actually i've worked with downloading files and this code
Response.ContentType = "application/octet-stream; name=" & oFile.Name
Response.AddHeader("content-disposition", "attachment;filename=" &
oFile.Name);
works perfectly
Regards
Martin Marinov
"Sleepy" <anonymous@discussions.microsoft.com> wrote in message
news:8DD2C6A6-7F48-49E3-8B3E-BD299F1DDF5B@microsoft.com...
> 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.Load
> 'Put user code to initialize the page here
>
> Dim sFilePath As String
> Dim oFile As IO.FileInfo
>
> sFilePath = Request.QueryString.Item("FilePath")
> oFile = New System.IO.FileInfo(sFilePath)
>
> ' Clear the current output content from the buffer
> Response.Clear()
>
> ' Specify that the response is a stream that cannot be read by the
client and must be downloaded
> Response.ContentType = "application/octet-stream"
>
> ' Add the header that specifies the default filename for the
Download/SaveAs dialog
> Response.AddHeader("Content-Disposition", "attachment filename=" &
oFile.Name)
>
> ' Add the header that specifies the file size, so that the browser can
show the download progress
> Response.AddHeader("Content-Length", oFile.Length.ToString())
>
> ' Send the file stream to the client
> Response.WriteFile(oFile.FullName)
>
> ' Stop the execution of this page
> Response.End()
>
> End Sub
>
- Next message: Vinodh Kumar[MS MVP]: "RE: Include asp code in aspx file"
- Previous message: Steve C. Orr [MVP, MCSD]: "Re: Include asp code in aspx file"
- In reply to: Sleepy: "Enabling a Client to Download a File"
- Next in thread: Sleepy: "Re: Enabling a Client to Download a File"
- Reply: Sleepy: "Re: Enabling a Client to Download a File"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|