AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=409&pId=-1
Downloading files to the browser with ADODB.Stream
page
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 18766/ 16

Downloading files to the browser with ADODB.Stream
Downloading files to the browser with ADODB.Stream
by Chris Garrett

This script demonstrates getting properties of a file, such as name and size, and using a response stream to send the file to the users browser.

VIEW SOURCE
/chrisg/tools/view-downloadfile.asp

GET THE SOURCE
/chrisg/tools/download.asp?file=downloadFile.asp

SEE IT IN ACTION
/chrisg/tools/download.asp?file=chrispic-small.gif

The script begins by calling the function "downloadFile" with the file we wish to download as a parameter, in this case getting it from the "file" request variable.

DownloadFile() first gets full path of specified file and checks to see if the file exists using the FileExists(strFilename) method of the filesystem object. It then gets the length of the file (the size) using the .size property of the file object. 

Lines 19 and 20 show how we create the stream object and in line 23 we set the stream to binary. Line 42 uses the loadfromfile method to begin the process to read in the file, and after the headers have been set between lines 49 and 52, the file is output using Response.Binarywrite and the contents of the streams "read".

Future improvements

I have fudged this script a bit by using a default content type of "octet", you could improve this scripts functionality by specifying the corrent mime type.


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-19 12:28:37 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search