Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    streaming files by ASP

    In ASP, I am streaming excel files back to the client using an ADODB.Stream .
    I set the Response.ContentType to excel and then do a Response.BinaryWrite myStream.Read .
    At the moment, the resulting xl file's name is that of the ASP which does the streaming.
    I want to know how to set the name of the xl file, and I suspect it can be done by adding an HTTP header.
    Does anyone know how I can do it?

  2. #2
    New Lounger
    Join Date
    Jan 2001
    Location
    New Zealand
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: streaming files by ASP

    Adam,
    You were right and the header line is this:

    Response.AddHeader "Content-Disposition", "inline; filename=yourfilename.xls"

    I am streaming auto extracting zip files but you would substitute any file name you wanted the browser to prompt the user with. With some older browsers this may not work but it does with Netscape 4.7 and IE 5.0.

    So the block of code in the ASP file would look like this:

    Response.ContentType ="application" Response.AddHeader "Content-Disposition", "inline; filename=yourfilename.exe"

    Const adTypeBinary = 1
    Dim objStream

    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile yourfilename.exe '(including full path if needed)
    Response.BinaryWrite objStream.Read

    objStream.Close
    Set objStream = Nothing

    In this case the browser will immediately prompt the use to either save or open the file with the file name that you have specified in the Content-disposition header (so this is effectively a downloader script) but as you must already know if you use a different content-type header such as "application/excel" or similar ( I'm not sure of the correct value for excel) then the browser will launch the correct application and open the file in that app.

    Hope this helps.
    Regards
    Simon Lampen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •