Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Open a PDF file using Response.Write

Posted on 2008-11-18
3
Medium Priority
?
1,987 Views
Last Modified: 2012-05-05
I want to store PDF's in a folder that is relative to the root directory - lets say "Temp".  Then I want to write them using the following code

 string path = "../temp/";
 Response.WriteFile(path+filename);
 Response.End();

I get the folloing error with this:   "Failed to map the path '/temp/myfile.pdf'.
0
Comment
Question by:BoggyBayouBoy
3 Comments
 
LVL 5

Accepted Solution

by:
P_Ramprathap earned 1000 total points
ID: 22991916
private void ReadPdfFile()
    {
        string path = @"C:\xxx/temp/myfile.pdf'
        WebClient client = new WebClient();
        Byte[] buffer =  client.DownloadData(path);

        if (buffer != null)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length",buffer.Length.ToString());
            Response.BinaryWrite(buffer);
        }

    }
 
Thanks
Ram
0
 
LVL 2

Assisted Solution

by:AshleighGreen
AshleighGreen earned 1000 total points
ID: 22992961
I may be wrong on this. But I'm pretty sure Ram's code, though very good, is missing a couple of small points.

As you have done in your example you will need a Response.End();

You will also need a filename (before the Response.End();)
Response.AddHeader("Content-disposition", "attachment; filename=" + "myPDF.pdf");
0
 
LVL 1

Author Closing Comment

by:BoggyBayouBoy
ID: 31518114
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

581 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