Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Flims, Switzerland
    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
    New Zealand
    Thanked 0 Times in 0 Posts

    Re: streaming files by ASP

    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.Type = adTypeBinary
    objStream.LoadFromFile yourfilename.exe '(including full path if needed)
    Response.BinaryWrite objStream.Read

    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.
    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