Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to save an exported pdf file . Now it's showing in download, once it Converted successfully. But i need to save this file to a folder. Please help me for resolve this issue.

following is my code
C#
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + filename + .pdf");
       Response.Cache.SetCacheability(HttpCacheability.NoCache);
       StringWriter sw = new StringWriter();
       HtmlTextWriter hw = new HtmlTextWriter(sw);

       HtmlForm frm = new HtmlForm();
       form1.Parent.Controls.Add(frm);
       frm.Attributes["runat"] = "server";
       frm.Controls.Add(tbl_Graph);
       frm.RenderControl(hw);
       StringReader sr = new StringReader(sw.ToString());
       Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
       HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

       PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
       pdfDoc.Open();
       CreatePages(pdfDoc, writer);
       pdfDoc.Close();
       Response.Write(pdfDoc);
       Response.End();
Posted

1 solution

 
Share this answer
 
Comments
ErBhati 27-Jan-14 3:11am    
i used this code

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=testpage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

this.Page.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
MemoryStream ms = new MemoryStream();
PdfWriter.GetInstance(pdfDoc, ms);
pdfDoc.Open();
htmlparser.Parse(sr);
FileStream file = new FileStream(Server.MapPath("~/Files/")+"pagepdf.pdf",FileMode.Create,System.IO.FileAccess.Write);
byte[] bytes = new byte[ms.Length];
ms.Read(bytes, 0,(int)ms.Length);
file.Write(bytes, 0, bytes.Length);
file.Close();
pdfDoc.Close();
ms.Close();


but gets Invalid URI: The hostname could not be parsed. error
JoCodes 27-Jan-14 3:18am    
Debug and check whether its a valid path

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