Open a PDF file using Response.Write

Posted on 2008-11-18
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/";

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

    Accepted Solution

    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";

    LVL 2

    Assisted Solution

    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");
    LVL 1

    Author Closing Comment


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now