Click here to Skip to main content
11,920,156 members (58,035 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET itextsharp
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.......
Posted 16-Oct-12 20:37pm
Edited 16-Oct-12 20: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
0 OriginalGriff 455
1 phil.o 170
2 CPallini 150
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,153
3 George Jonsson 2,810
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2015
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