Solved

File name in ADODB.Stream

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Leverage browser caching 2 55
Group by correlation 4 55
Import csv files to MS SQL 5 73
Need help editing script 3 65
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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

14 Experts available now in Live!

Get 1:1 Help Now