Force Save As prompt, BinaryWrite ?

Posted on 2003-03-23
Medium Priority
Last Modified: 2012-06-27
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 www.aspfaq.com:

    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.
Question by:Blarpie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 33

Expert Comment

ID: 8189736
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.

LVL 28

Expert Comment

ID: 8189873
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"
LVL 10

Accepted Solution

apollois earned 200 total points
ID: 8190963
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,
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 8191031
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.

Author Comment

ID: 8191224
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.


Author Comment

ID: 8206612
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.
LVL 10

Expert Comment

ID: 8206658

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 (http://www.experts-exchange.com/Community_Support/qAskQuestion.jsp).  Include a link to this question, and the new grade.

Best Regards,

Author Comment

ID: 8870958
Sorry, haven't been here in a while and you are correct.
Posted the correction to the community support.


Expert Comment

ID: 8873471
Grade change to an A.

EE Moderator

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question