Re: Enabling a Client to Download a File

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Martin Marinov (memmarinov_at_mecrossroad.bg)
Date: 06/03/04


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
>



Relevant Pages

  • Re: Im using FreeTextBox and would like to save the text in a client file.
    ... You should be able to force a download dialog using: ... http://support.microsoft.com/kb/260519/en-us (content-disposition header). ... I'm using FreeTextBox and would like to save the text on the client. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: SBS 2003 Premium: how to allow FTP .EXE downloads
    ... Disable the problematic client XP firewall, ... click to check the "Hide All Microsoft Services" ... Is the FTP server on SBS? ... Download the file from the following URL: ...
    (microsoft.public.windows.server.sbs)
  • Re: detecting successful downloads and browser buffering
    ... connection is to the proxy, not the client. ... to bullet proof the download, you would need to supply an active/x control ... that wrote the file and updated the server on successful write to disk. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Massive packet latency on T-Mobile 3G
    ... by contrast an ADSL connection is only limited in this way if either the ... so it is not the client in the Nokia ... ssh and using pop3 results in a successful download ... I have edited the appropriate message on the server to alter its ...
    (uk.telecom.mobile)
  • Re: Cant send back null class reference as SOAP Header?
    ... State is maintained on the server (no ... the client actually maintains the key to the state ... If they then retry the request, the flag won't be sent, will it? ... The header is defined as Direction.InOut on every ...
    (microsoft.public.dotnet.framework.webservices)