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