Solved

File name in ADODB.Stream

Posted on 2006-06-22
3
438 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Auto Submit on dropdown box 14 72
Pass through dll 2 91
is this a cms? 8 67
Html form and modal / img src -problem 3 28
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 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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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