Click here to Skip to main content
13,054,615 members (66,846 online)
Rate this:
Please Sign up or sign in to vote.
I am creating a pdf. now it is directly downloading to the users default browsers downloads. I want to this pdf to only save at the specified location without user notification. I will provide download option to user later in another grid for the same pdf.
I tried the following for this...

HttpResponse response = HttpContext.Current.Response;
        Response.Buffer = true;
        //string path = Server.MapPath("~/desktopmodules/Downloads/");
        //string filepath = path + budgetName;
        //PdfWriter.GetInstance(document, new FileStream(filepath, FileMode.Create));
        response.ContentType = "application/octet-stream";
        string path = Server.MapPath("~/DesktopModules/Downloads/");
        response.AddHeader("Content-Disposition", "filename=" + budgetName + ".pdf");
        // step 1: creation of a document-object
        //Document document = new Document(PageSize.LETTER);
        // step 2: we create a writer that listens to the document
        //PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);

but i wont get succeed so please help me to set the download path of the pdf.
please help.......
<edited and="" added="" code="" block="" mark="" -="" milind="" />
Posted 16-Oct-12 19:37pm
Updated 16-Oct-12 19:41pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


See the below link. I think it might be help you.[^]

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This is something i have used earlier. Your scenario could be different, but PDFDocument usage will be same.
using System;
using System.IO; 
using iTextSharp.text.pdf;
namespace TestApplication
    public partial class dialog : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            PdfPTable SummaryTable = new PdfPTable(2);             
            using (FileStream fs = new FileStream(Server.MapPath("YourRelativeFilePath"), FileMode.Create))
                using (iTextSharp.text.Document doc = new iTextSharp.text.Document())
                    PdfWriter writer = PdfWriter.GetInstance(doc, fs);

Sample usage of 'YourRelativeFilePath':
FileStream fs = new FileStream(Server.MapPath("~\\MailUploads\\SearchReport\\" + sFileName), FileMode.Create)

MailUploads is a folder inside my project and inside it there is a subfolder SearchReport, sFileName is the string variable which holds the name with which the pdf should be saved.

hope this helps.
ChandanBadgujar 17-Oct-12 2:41am
Is is not accepting the relative path please can u provide some example for this, please....
TheCoolCoder 17-Oct-12 3:40am
Check the updated solution there is a sample path added.
TheCoolCoder 17-Oct-12 2:59am
Please paste your pdf saving function here, let me have a look at it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100