Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

Force Download and Redirect

Posted 17 Feb 2004 19:13:06
1
has voted
17 Feb 2004 19:13:06 Lee Smith posted:
I'm hoping that somebody is clever enough to solve my problem,

I have created a form on a page that a user has to fill out before downloading a document. On submitting the form the page redirects to a mailer.asp page that sends them a confirmation e-mail. This page then redirects to a page where I would like the download to start automatically. When the download starts the page in the background is still the form page that the user filled out. I am using the BUD Force Download extension in Dreamweaver.

The page itself doesn't seem to load properly because the code from the extension is put in the head of the document, so it seems that nothing past the download code gets processed.

Is there any way that I can put this code somewhere else in the file to make it happen after the page has loaded?

Lee Smith

Replies

Replied 18 Feb 2004 14:48:22
18 Feb 2004 14:48:22 Lee Diggins replied:
Hi Lee

Can't help you with the extension, but i do have a very neat script that will force a download using asp.

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 18 Feb 2004 15:44:50
18 Feb 2004 15:44:50 Lee Smith replied:
Thanks Digga,

Any help would be greatly appreciated. Can you post the script here or email it to me.

Cheers,

Lee

Lee Smith
Replied 18 Feb 2004 16:09:56
18 Feb 2004 16:09:56 Lee Diggins replied:
Hi Lee

I found this script a while ago and use it often. For dynamic downloads the file will need some set up and maybe the calling page too. The easiest way to run this is to have this code on a single page without any other code and call this page using a hyperlink on another page. This will start the download dialogue as normal, leaving the page behind 'as is' when it initiated the call. You just need to specify the path and filename and if the MIME type isn't listed in the select case, then add it.

Post back here for any further questions.

Here goes:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
'--------------------------------------------
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName

Const adTypeBinary = 1

strFilePath = "path here including filename, I use mappath - c:\myFiles\text1.txt - that sort of thing"
'strFileSize = optional
strFileName = "filename here - text1.txt"

Response.Clear

'*******************************
' Requires MDAC 2.5 to be stable
' I recommend MDAC 2.6 or 2.7
'*******************************

Set objStream = Server.CreateObject("ADODB.Stream"
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

strFileType = lcase(Right(strFileName, 4))

' Feel Free to Add Your Own Content-Types Here
Select Case strFileType
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".asp"
ContentType = "text/asp"
Case ".txt"
ContentType = "text/plain"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select

Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Response.AddHeader "Content-Length", strFileSize
' In a Perfect World, Your Client would also have UTF-8 as the default
' In Their Browser
Response.Charset = "UTF-8"
Response.ContentType = ContentType

Response.BinaryWrite objStream.Read
Response.Flush

objStream.Close
Set objStream = Nothing

%>

Thanks to www.psacake.com for this script

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 18 Feb 2004 16:23:23
18 Feb 2004 16:23:23 Lee Smith replied:
That'll do the trick!!

Thanks Digga, much appreciated

Lee Smith
Replied 19 Feb 2004 21:14:30
19 Feb 2004 21:14:30 Matthijs Horsman replied:
nice script, but be aware that files bigger the 4mb won;t work on an windows2003 server. You will het a buffer excedeed message. You will need to use a component (www.aspupload.com) or change the metabase.xml file

Matthijs
----------------
DWMX/W-XP-PRO/IIS/ASP-VB/MS-SQL

Edited by - matthijshorsman on 19 Feb 2004 21:16:17
Replied 20 Feb 2004 11:16:52
20 Feb 2004 11:16:52 Lee Diggins replied:
Is that the AspBufferingLimit Matthijs?

We're upgrading to 2003 right now, any chance you can point me in the right direction for concise information on the metabase settings in IIS?

Thanks.

Digga

Sharing Knowledge Saves Valuable Time!!!

Reply to this topic