“Save As” Dialog Box for Streaming File

To download files using a “Save As” dialog box try this code:

        Select Case FileExt
            Case “gif” ContentType = “image/gif”
            Case “tif” ContentType = “image/tiff”
            Case “jpg” ContentType = “image/jpeg”
            Case “pdf” ContentType = “application/pdf”
            Case “avi” ContentType = “video/x-msvideo”
            Case “mp3” ContentType = “audio/mpeg”
            Case “mpg” ContentType = “video/mpeg”
            Case “wav” ContentType = “audio/wav”
            Case “rar” ContentType = “application/x-rar-compressed”
            Case “zip” ContentType = “application/x-zip-compressed”
            Case “exe” ContentType = “application/x-msdownload”
            Case Else
             ‘ FilePath = “”
             ContentType = “application/x-msdownload”
        End Select

        Response.Clear
        Response.Buffer = False
        Dim adoStream
        Set adoStream = Server.CreateObject(“ADODB.Stream”)
        adoStream.Open()
        adoStream.Type = 1
        adoStream.LoadFromFile(FilePath + “/” + FileName)
        Response.AddHeader “Content-Disposition”, “attachment;filename=” & Right(FileName,Len(FileName)-InStr(FileName,”/”))
        Response.ContentType = ContentType
        Response.BinaryWrite(adoStream.Read())
        adoStream.Close
        Set adoStream = Nothing
        Response.End

The ASP buffering limit is about 4 megs. Files larger than that will give an error like this:

   “Response Buffer to exceed its configured limit”

To stream out files larger than 4 Meg you can increase the “AspBufferingLimit” value. Edit the MetaBase.xml file in the C:\WINDOWS\system32\inetsrv folder. The default value is 4194304. Check the “Enable Direct Metabase Edits” check box before editing this file and you will not need to stop and start the WWW service.