File Download


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: File Download

  1. #1
    BrianP Guest

    File Download


    In ASP.NET how can I download a memory stream which contains the dynamically
    created data to a site as if the data were the contents of a file on the
    server.

    I cannot use Response.OutputStream(), .BinaryWrite() or similar as the receiver
    receives bytes and not a file which needs to be saved to their hard disk

    Hope someone knows the answer

    Thanks
    Brian



  2. #2
    Patrice Scribe Guest

    Re: File Download

    You can do so using the following header :

    Content-disposition: attachment; filename=fname.ext

    See
    http://support.microsoft.com/default...en-us%3B260519
    for details (doesn't work for 4.01 because of a bug).

    --

    "BrianP" <vb.@127.0.0.1> a écrit dans le message de news:
    3ea79f7f$1@tnews.web.devx.com...
    >
    > In ASP.NET how can I download a memory stream which contains the

    dynamically
    > created data to a site as if the data were the contents of a file on the
    > server.
    >
    > I cannot use Response.OutputStream(), .BinaryWrite() or similar as the

    receiver
    > receives bytes and not a file which needs to be saved to their hard disk
    >
    > Hope someone knows the answer
    >
    > Thanks
    > Brian
    >
    >



  3. #3
    Russell Jones Guest

    Re: File Download

    The receiver always receives bytes. It's how the receiver interprets those
    bytes that matters--and you control that by setting the MIME type of the
    response, via the Response.ContentType property.

    Here's an example that downloads a "file" to the browser:

    ' respond with a binary stream formatted as a .dat file.
    Response.ContentType = "APPLICATION/OCTET-STREAM"
    Dim downloadFilename As String = "yourfile.dat"
    ' set the suggested filename--user will see a SaveAs dialog
    Response.AddHeader("Content-Disposition", "filename=""" &
    downloadFilename & """")

    'send a stream of bytes
    Dim s As String = "This is the downloaded file."
    Dim b() As Byte = New System.Text.UnicodeEncoding().GetBytes(s)
    Response.OutputStream.Write(b, 0, b.Length)
    Response.End()



    "BrianP" <vb.@127.0.0.1> wrote in message
    news:3ea79f7f$1@tnews.web.devx.com...
    >
    > In ASP.NET how can I download a memory stream which contains the

    dynamically
    > created data to a site as if the data were the contents of a file on the
    > server.
    >
    > I cannot use Response.OutputStream(), .BinaryWrite() or similar as the

    receiver
    > receives bytes and not a file which needs to be saved to their hard disk
    >
    > Hope someone knows the answer
    >
    > Thanks
    > Brian
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center