Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...

C#
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.......
<edited and="" added="" code="" block="" mark="" -="" milind="">
Posted
Updated 16-Oct-12 19:41pm
v2

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.
 
Share this answer
 
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...
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900