Click here to Skip to main content
12,074,808 members (57,208 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET itextsharp
Hi,
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.Clear();
        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
MT_10.9K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

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

http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog[^]

Thanks,
Viprat
  Permalink  
Rate this: bad
 
good
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);
                    
                    doc.Open();
                    doc.Add(SummaryTable);
                    
                    doc.Close();
 
                }
                fs.Close();
            }
        }
 
         
    }
}

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.
  Permalink  
v3
Comments
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
Web04 | 2.8.160208.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2016
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