0

I need to read the pdf file from sharepoint document library and need to update and save it in another folder.

By google, I got to know that we can read text files from document library from the below link and is working fine for me. http://www.c-sharpcorner.com/UploadFile/0e18a8/read-a-file-in-a-document-library-in-sharepoint-2013-using-c/

is it possible to read pdf files as well and how to update and store them.

kindly help on this.

3
  • 1
    On google, search for how to read pdf file using C#. You will get reference. From SharePoint perspective i guess you will need only pass the filepath and person running this programs needs to have access on that path
    – P S
    Nov 9, 2016 at 6:29
  • Thanks, I have used c# code using itext sharp for my requirement and it is working fine...thank you :) Dec 13, 2016 at 9:42
  • Hi Pradeep, you can add what you have done as answer and accept it. It may help other members in future.
    – P S
    Dec 13, 2016 at 11:22

1 Answer 1

0

I have read file from sharepoint document library and saved into local server path using following code.

using SP = Microsoft.SharePoint.Client;
ClientContext context = new ClientContext(ConfigurationManager.AppSettings["WebURL"].ToString());
Web web;
SP.List docLibName;
SP.ListItemCollection docLibColl;
SP.ListItem item;
SP.File file;
SP.CamlQuery caml = new SP.CamlQuery();

item = docLibName.GetItemById(Convert.ToInt32("Id of the document"));
file = item.File;
context.Load(item);
context.Load(file);
context.ExecuteQuery();
var fileInfo = SP.File.OpenBinaryDirect(context, item.File.ServerRelativeUrl);

Stream fs = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, file.ServerRelativeUrl).Stream;
byte[] binary = ReadFully(fs);
        if (System.IO.File.Exists("sourceFilePath"))
        {
            System.IO.File.Delete("sourceFilePath");
            using (var fileStream = System.IO.File.Create("sourceFilePath"))
                {
                     fileInfo.Stream.CopyTo(fileStream);
                }
         }
         else
         {
            using (var fileStream = System.IO.File.Create("sourceFilePath"))
                {
                      fileInfo.Stream.CopyTo(fileStream);
                 }    
          }

once I saved file from sharepoint library to my local server, The code used for extraction and updating pdf is posted at Replace Text using ItextSharp

please reach me for any queries

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.