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

Discussion in 'ASP .Net' started by Ken Cox [Microsoft MVP], Aug 16, 2003.

  1. 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/security_bulletins/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
    Ken Cox [Microsoft MVP], Aug 16, 2003
    #1
    1. Advertising

  2. Ken Cox [Microsoft MVP]

    mandelbort Guest

    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/security_bulletins/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
    >
    >
    mandelbort, Aug 17, 2003
    #2
    1. Advertising

  3. 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/security_bulletins/ms03-026.asp



    "mandelbort" <> wrote in message
    news:O$$...
    Thanks! :) it works fine;
    any ideas about the code efficiency?
    Mik
    Ken Cox [Microsoft MVP], Aug 17, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mandelbort
    Replies:
    1
    Views:
    460
    S. Justin Gengo
    Aug 18, 2003
  2. Replies:
    2
    Views:
    4,758
  3. Michael Foord

    HTTP Headers to make a download

    Michael Foord, Oct 12, 2004, in forum: Python
    Replies:
    2
    Views:
    343
    Michael Foord
    Oct 13, 2004
  4. Ian
    Replies:
    2
    Views:
    1,931
  5. Nguyen

    Download only http headers

    Nguyen, Nov 30, 2006, in forum: Ruby
    Replies:
    2
    Views:
    112
    Nguyen
    Nov 30, 2006
Loading...

Share This Page