Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: How to download file from server using http headers?

Reply
Thread Tools

Re: How to download file from server using http headers?

 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      08-16-2003
You can tell it the filename by added this header just before you do the write:

Response.AddHeader("Content-Disposition", "attachment;filename=test.aaa")

Ken
MVP [ASP.NET]

--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp



"mandelbort" <> wrote in message
news:...
Hi, i'm tryng to make a asp.net file manager to download files that are on a
server;
supposing i want to download the file c:\test\test.aaa, the code i have
written is:


#########################################

Dim fStream As New System.IO.FileStream(path & file, _
IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)

Dim b(fStream.Length) As Byte

Response.Clear()
Response.ClearContent()
Response.ClearHeaders()

Response.ContentType = "application/unknown"

fStream.Read(b, 0, fStream.Length)

Response.BinaryWrite(b)

Response.End()

fStream.Close()
fStream = Nothing

#####################################

this method works fine, but there are 2 problems:
1. when the dialog for file saving appears, it prompt to save a file with
the name of the aspx page, and not with the name of the file being
downloaded;
2. i suppose that it is not very efficient to open the file with filestream,
copy it into a byte array and then output it to the page: there is some
method more efficient??

Thanks, Mik


 
Reply With Quote
 
 
 
 
mandelbort
Guest
Posts: n/a
 
      08-17-2003
Thanks! it works fine;
any ideas about the code efficiency?
Mik

"Ken Cox [Microsoft MVP]" <> ha scritto nel
messaggio news:...
> You can tell it the filename by added this header just before you do the

write:
>
> Response.AddHeader("Content-Disposition", "attachment;filename=test.aaa")
>
> Ken
> MVP [ASP.NET]
>
> --
> Microsoft MVPs have a question for *you*: Are you patched against the

Worm?
> http://www.microsoft.com/security/se...s/ms03-026.asp
>
>
>
> "mandelbort" <> wrote in message
> news:...
> Hi, i'm tryng to make a asp.net file manager to download files that are on

a
> server;
> supposing i want to download the file c:\test\test.aaa, the code i have
> written is:
>
>
> #########################################
>
> Dim fStream As New System.IO.FileStream(path & file, _
> IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
>
> Dim b(fStream.Length) As Byte
>
> Response.Clear()
> Response.ClearContent()
> Response.ClearHeaders()
>
> Response.ContentType = "application/unknown"
>
> fStream.Read(b, 0, fStream.Length)
>
> Response.BinaryWrite(b)
>
> Response.End()
>
> fStream.Close()
> fStream = Nothing
>
> #####################################
>
> this method works fine, but there are 2 problems:
> 1. when the dialog for file saving appears, it prompt to save a file with
> the name of the aspx page, and not with the name of the file being
> downloaded;
> 2. i suppose that it is not very efficient to open the file with

filestream,
> copy it into a byte array and then output it to the page: there is some
> method more efficient??
>
> Thanks, Mik
>
>



 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      08-17-2003
Hi Mik,

Sorry, not sure what efficiency you're referring to. The use of AddHeader adds
very very little to the output.

Ken

--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp



"mandelbort" <> wrote in message
news:O$$...
Thanks! it works fine;
any ideas about the code efficiency?
Mik


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/822319ev1'. 'HTTP/1.1 500 Internal Server Error'. chanmm ASP .Net 2 09-07-2010 07:37 AM
multitask http server (single-process multi-connection HTTP server) lkcl Python 6 07-15-2010 10:39 PM
Can I change the response URL to http://server/page.XLS instead of http://server/page.ASPX ? guillermojco@gmail.com ASP .Net 3 04-26-2007 04:49 AM
Re: How to download file from server using http headers? mandelbort ASP .Net 1 08-18-2003 01:26 PM



Advertisments