Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Convert Word, Excel and PPT to PDF

$
0
0

Hi, 

Below is my code, which is generating the PDF file inside the document library but it is getting corrupted, any idea what am i doing wrong?

  var list = clientContext.Web.Lists.GetByTitle(listTitle);
                clientContext.Load(list.RootFolder);
                clientContext.ExecuteQuery();

                CamlQuery c = CamlQuery.CreateAllItemsQuery();
                ListItem lstitm = list.GetItemById(10);

                Microsoft.SharePoint.Client.File spFile = lstitm.File;
                clientContext.Load(spFile);
                Microsoft.SharePoint.Client.ClientResult<System.IO.Stream> bin = spFile.OpenBinaryStream();
                clientContext.ExecuteQuery();


                var fileCreationInformation = new FileCreationInformation();
                byte[] blob = null;

                byte[] buffer = new byte[16 * 1024];
                using (MemoryStream ms = new MemoryStream())
                {
                    int read;
                    while ((read = bin.Value.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    blob = ms.ToArray();
                }

 fileCreationInformation.Content = blob; //bytes;
                fileCreationInformation.Overwrite = true;
                fileCreationInformation.Url = url + "/" + "Shared%20Documents" + "/Payslip_New.pdf";
                list.RootFolder.Files.Add(fileCreationInformation);
                clientContext.ExecuteQuery();
Can anyone suggest what is going wrong, as i am simply converting a word document to PDF.
 

Thanks, Parth


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>