Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Through provider hosted app for Sharepoint 2013, I am accessing doc lib document and copying that content to a new document and uploading it into doclib.


Getting 401 error at ---ClientOM.File.OpenBinaryDirect(clientContext, (string)listItem["FileRef"]);

Page_Load method:
var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

MemoryStream memStream = new MemoryStream();



using (var clientContext = spContext.CreateAppOnlyClientContextForSPHost())
{

List docLib = clientContext.Web.Lists.GetByTitle("TestDocLib");
ClientOM.ListItem listItem = docLib.GetItemById(1);

clientContext.Load(docLib);
clientContext.Load(docLib.RootFolder);
clientContext.Load(listItem);
clientContext.ExecuteQuery();


try
{
FileInformation fileInformation = ClientOM.File.OpenBinaryDirect(clientContext, (string)listItem["FileRef"]);

CopyStream(fileInformation.Stream, memStream);


string serverRelativeUrl = docLib.RootFolder.ServerRelativeUrl + "/test1.docx";


memStream.Seek(0, SeekOrigin.Begin);
ClientOM.File.SaveBinaryDirect(clientContext,
serverRelativeUrl, memStream, true);
}



catch (Exception exp)
{

}

}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900