I'm not sure where I found this code on the net, but this is what I use to
download a file:
' This part gets the filename from the querystring
' and builds a path to that file
Dim strFile, strPath
strFile = Request.QueryString("file")
strPath = "/download/" & strFile
strPath = Server.MapPath(strPath)
' This adds http headers that tell the browser what to do w/the file
' The first header tells the browser to download the file, not display it
' It also gives a filename to call the downloaded file
Response.AddHeader "content-disposition","attachment; filename=" & strFile
' The browser will attempt to appropriately handle the file, by opening
' it using a plug-in or other application. Since I want the file to just
' download to the user's computer, I set the ContentType to something
' that will always be saved and not passed to another application
Response.ContentType = "application/octet-stream"
' Now I save the file using an ADO Stream
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Open
objStream.LoadFromFile(strPath)
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream = Nothing
Response.End
Hope this helps.
Wade
on 10/18/02 10:55 AM, EXT-Sauceda, Gilbert at [EMAIL PROTECTED]
wrote:
> I am interested in learning how to do this.
> I don't clearly understand how the syntax would look on an ASP page.
> Is there a reference on the net where I could see a sample?
>
> thanks.
>
> -----Original Message-----
> From: Wade Armstrong [mailto:wade_lists@;runstrong.com]
> Sent: Friday, October 18, 2002 10:46 AM
> To: ActiveServerPages
> Subject: Re: Force download
>
>
> on 10/18/02 1:01 AM, Rupert Killick at [EMAIL PROTECTED] wrote:
>
>> Response.ContentType = rs("sMIMEType")
>
> Try:
> Response.ContentType = "application/octet-stream"
> or
> Response.ContentType = "application/x-msdownload"
>
> either should force the browser to download rather than being handled as is
> appropriate for the mime-type of the file you're sending to the browser.
>
> Wade
>
>
---
You are currently subscribed to activeserverpages as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]