LogoASPAlliance: Articles, reviews, and samples for .NET Developers
Downloading files to the browser with ADODB.Stream
by Chris Garrett
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27891/ 131

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.




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-2019  |  Page Processed at 2019-10-19 8:22:49 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search