Hopefully this is the right place to post this....

I've been using this code for the past couple months to force the
browser to raise a Save As window for users when they click on certain
files.

Relevant links: http://support.microsoft.com/kb/q260519/,
http://support.microsoft.com/kb/193998/

<%
    Response.ContentType = "application/x-unknown" ' arbitrary
    fn = "3.pdf"
    FPath = server.MapPath("/wm/annualreport/09/") & fn
    Response.AddHeader "Content-Disposition","attachment; filename=" &
fn

    Set adoStream = CreateObject("ADODB.Stream")
    adoStream.Open()
    adoStream.Type = 1
    adoStream.LoadFromFile(FPath)
    Response.BinaryWrite adoStream.Read()
    adoStream.Close
    Set adoStream = Nothing

    Response.End
%>

This works fine, but I've just started using it with files that are
over 4MB and the browser seems to choke on that, saying that a file
cannot be found (both with the online server and my local IIS 7.5).

I found the following script, which is supposed to make it work for
large files (http://classicasp.aspfaq.com/general/how-do-i-prompt-a-
save-as-dialog-for-an-accepted-mime-type.html), by turning the buffer
off and breaking the file up into chunks. But the script doesn't work
with any file, even small ones. Any idea what I'm missing?

Thanks in advance!

Seth

<%

    Response.Buffer = False
    Server.ScriptTimeout = 30000

    Response.ContentType = "application/x-unknown" ' arbitrary
    fn = "3.pdf"
    FPath = "c:\inetpub\wwwroot\wm\annualreport\09\"
    Response.AddHeader "Content-Disposition", "attachment; filename="
& fn

    Set adoStream = CreateObject("ADODB.Stream")
    chunk = 2048
    adoStream.Open()
    adoStream.Type = 1
    adoStream.LoadFromFile(FPath)

    iSz = adoStream.Size

    Response.AddHeader "Content-Length", iSz

    For i = 1 To iSz \ chunk
        If Not Response.IsClientConnected Then Exit For
        Response.BinaryWrite adoStream.Read(chunk)
    Next

    If iSz Mod chunk > 0 Then
        If Response.IsClientConnected Then
            Response.BinaryWrite adoStream.Read(iSz Mod chunk)
        End If
    End If

    adoStream.Close
    Set adoStream = Nothing

    Response.End
%>

Reply via email to