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”.
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.
One should always try to be more productive, even if it is only to speed up the dull bits so you have more time to do the fun stuff ;O)
The following three articles show how you can automate routine tasks with ASP, Windows Scripting Host (WSH) and SQL Server Data Transformation Services (DTS).
Each article stands on its own, but there is no reason why you could not mix and match as they are all complementary and execute in their own environments.
We start with DTS as this is the tool I have found most useful in automating workflow or moving/importing/exporting data at the push of a button ..
- Execute DTS from ASP/SProc
- Run command lines from ASP
- Call a web page from command line