Solved

File name in ADODB.Stream

Posted on 2006-06-22
3
429 Views
Last Modified: 2006-11-18
Hi Experts,

To offer visitors a download without giving away the path to the file, I implemented the code as described in Microsofts Knowledge Base article "Use of the ADODB.Stream Object to Send Binary Files to the Browser through ASP" (http://support.microsoft.com/support/kb/articles/q276/4/88.asp).

Most of the files I want to send are PDF, so I changed
            Response.ContentType = "application/octet-stream"
to
            Response.ContentType = "application/pdf"

I've also set
        Response.AddHeader "Content-Disposition", "attachment; sFilename=" & objFile.Name

still, the browser suggests as a file name the name of the asp file that sends the pdf. I checked with a debug line
Response.Write objFile.Name
and it outputs the correct value. What is wrong here?
0
Comment
Question by:WebJoe
3 Comments
 
LVL 13

Accepted Solution

by:
jmundsack earned 250 total points
ID: 16968779
Could it be that it's "Filename=" not "sFilename="?
0
 
LVL 3

Expert Comment

by:CubeRoot
ID: 16969050
This is a procedure that I use. I actually got the coding from here some time ago. A sample procedure call is at the bottom.

' ================================================================================
' === This procedure writes a file directly to the client.
' === This keeps the client from bookmarking the file directly.
' ================================================================================
Sub WriteFileToBrowser(ByVal sFilePath, ByVal sContentType, ByVal sDisplayName)
      On Error Resume Next
    Dim oStream
    Set oStream = Server.CreateObject("ADODB.Stream")
    oStream.Type = 1
    oStream.Open
    oStream.LoadFromFile sFilePath
    Response.ContentType = sContentType
    Response.AddHeader "Content-Disposition", "filename=" & sDisplayName
    Response.AddHeader "Content-Length", oStream.Size
    Response.BinaryWrite oStream.Read
    oStream.Close
    Set oStream = Nothing
    If Err.number > 0 Then Response.Write err.Description & "<BR>"
    On Error Goto 0
End Sub


Call WriteFileToBrowser(Server.MapPath("/") & "\Downloads\" & sFilename,"application/octet-stream", sFilename)
' Server.MapPath("/") & "\Downloads" & sFilename could point just about anywhere as long as your IUSR_???? account has permission to the file.

0
 

Author Comment

by:WebJoe
ID: 16970061
Of course, I must have run a search/replace and replaced one time too many ... thank you for your trained eye
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now