Force Save As prompt, BinaryWrite ?

Hi all,

Sorry if this is real newbie stuff, hopefully you can provide me with directions on were to go from here.
I've created a directory browsing code which works without any problem.
The problem is that when a user (or me, still in development) tries to download a file it opens the file in the browser, instead of having the Save As prompt.
So I want to force the Save As prompt.
So I searched the net and found that this was possible, I found a good example using the Response.BinaryWrite method. The problems with BinaryWrite is that it doesn't handle big files very well (AFAIK).

I read on msdn that the default buffer size is 4MB.
I guess this i right because I get "virtual memory" errors on the server if I try to download a 50MB file.
So is this fixable ?

Here is the example code from

    fn = "ml1.jpg"
    FPath = "c:\" & fn
    Response.ContentType = "application/asp-unknown" ' arbitrary
    Response.AddHeader "content-disposition","attachment; filename=" & fn
    Set adoStream = Server.CreateObject("ADODB.Stream")
    adoStream.Type = 1
    Response.BinaryWrite adoStream.Read()
    adoStream.Close: Set adoStream = Nothing

I've modified the code so that it's checking the path and file name that get send from the link.
Otherwise it's the same code.
Who is Participating?
apolloisConnect With a Mentor Commented:
Hi Blarpie,

Two thoughts:

     1.     Usually files of significant size are compressed using something like PKZIP/WINZIP before downloading.  If you convert your large docs to .zip, then the normal IIS download will work fine.
     2.     If you have a lot of files to download, and of significant size, then you may need a commercial download component that can handle large file sizes and resumable downloads.

Here's one example:

SoftArtisans FileUp 4.0
FileUp also includes file download and file management controls, which allow you to simply and easily download files from the Web server to the user's browser, manipulate files, change ACLs and permissions, and register DLLs, all in a single, easy-to-use package.

Best Regards,
How about trying using FileSystemObject method?

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile("C:\yourfile.jpg")

Response.Buffer = True

Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-disposition", "attachment; filename=yourfile.jpg"

Do While Not objTS.AtEndOfStream
   strChunk = objTS.Read(32)
   strTmp = "" 
   For i = 1 to Len(strChunk)
       strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
   Response.BinaryWrite strTmp

Set objTS = Nothing
Set objFSO = Nothing

Not sure if it works for 50MB file. Try it out.

basically the ADODB.Stream method should be a lot better. Except that you have a memory problem on the server with large files. That is not because of the method used, but because of hardware limitations.

Have you tried this one (not sure it will work..)

Response.ContentType = "application/octet-stream"
Response.redirect "yourfile.jpg"
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

BlarpieAuthor Commented:
Thanks for the responses, I'll try each and see if that fix the problem.

Apollois, the only problem with FileUp as I see it, is that it's overkill for my purpose/plan.
But I'll check it out.
BlarpieAuthor Commented:
Ok, when I tried to use the FileSystemObject I didn't get a memory problem but it shut down the download after about 13MB and the transfer rate was 100KB/s on a 100Mb LAN. So it may not be the best thing or it's the same symtom but displayed differently.

The redirect thing doesn't work in my case unless I move the fileshare-directory within the web-structure.
But that may be the easiest way around the problem because then people can use "right-click" if they want to download the file.

BlarpieAuthor Commented:
It seemed like there was no easy/cheap way to get the functionality were I wanted so I accept Apollois answer directing me to a commercial solution.
Thanks guys.

Thanks for selecting my comment as the answer.  But why the grade of "B"?

I thought I had answered your question completely and correctly.  Is there any directly related information that you need to answer the original question?

Please see How Do I Know What Grade to Give?

If you wish to change the grade, you can post a zero-point question with Community Support (  Include a link to this question, and the new grade.

Best Regards,
BlarpieAuthor Commented:
Sorry, haven't been here in a while and you are correct.
Posted the correction to the community support.

Grade change to an A.

EE Moderator
All Courses

From novice to tech pro — start learning today.