Hi Frriends,
I have created Pdf file from SharePoint List data
DataTable dt = GetProductsData();
GridView GridView1 = new GridView();
GridView1.DataSource = dt;
GridView1.DataBind();
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=CustomerInfo.pdf");
StringWriter sWriter = new StringWriter();
HtmlTextWriter hTWriter = new HtmlTextWriter(sWriter);
GridView1.RenderControl(hTWriter);
StringReader sReader = new StringReader(sWriter.ToString());
Document pdf = new Document(PageSize.A4);
HTMLWorker worker = new HTMLWorker(pdf);
PdfWriter.GetInstance(pdf, Response.OutputStream);
pdf.Open();
worker.Parse(sReader);
pdf.Close();
Response.Write(pdf);
Response.Flush();
Response.End();
its working fine but i want store this Pdf file in to my document library please can you help this query
Regards,
Surya
Loading

Veena SardaRank #79 · 24.5K reputationPosted Sep 30, 2012, 11:44 PM EDT
1. Get the file in ByteArray
byte[] contents = new byte[];
Response.OutputStream.Write(contents , 0, contents.Length);
2. Get the Site and using SPFileCollection's Add method upload the stream as a file in the document library - in this case My Documents
SPSite spSite = new SPSite("http://xxx/");
SPWeb spWeb = spSite.OpenWeb();
spWeb.Files.Add("http://xxx/My%20Documents/" + strFileName, contents);Surya Narayana3 reputationPosted Oct 10, 2012, 9:07 PM EDT
Thank for your suggestion.
i will try it
Thanks,
Surya