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
Surya NarayanaPosted Oct 11, 2012, 1:07 AM
Thank for your suggestion.
i will try it
Thanks,
Surya
Veena SardaPosted Oct 1, 2012, 3:44 AM
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);