Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

File name in ADODB.Stream

Posted on 2006-06-22
3
Medium Priority
?
443 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 750 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

618 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