Solved

File name in ADODB.Stream

Posted on 2006-06-22
3
441 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
[X]
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
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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