While loading ClientContext in Provider Hosted Application for SharePoint Online 2013 to read file in InfoPath's XML and generate another XML file to be uploaded in another Document Library.
Tried Multiple Solution listed below.
FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef.ToString());
gives error
at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() at Microsoft.SharePoint.Client.File.OpenBinaryDirect(ClientContext context, String serverRelativeUrl) at SharePointAppWithAzureWeb.Services.RemoteEventReceiver1.ProcessOneWayEvent(SPRemoteEventProperties properties)
Tried this code
var fileRef = listItem.FieldValues["FileRef"]; var srcWeb = context.Web; Microsoft.SharePoint.Client.File file = srcWeb.GetFileByServerRelativeUrl(fileRef.ToString()); string nLocation = context.Web.ServerRelativeUrl.TrimEnd('/') + "/" + "testdert".Replace(" ", "") + "/" + file.Name; FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, file.ServerRelativeUrl); Microsoft.SharePoint.Client.File.SaveBinaryDirect(context,nLocation , fileInfo.Stream, true);
giving error
The property or field 'ServerRelativeUrl' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Third solution I tried
FileCreationInformation newFile = new FileCreationInformation(); newFile.Content = System.IO.File.ReadAllBytes(@"http/spe196:2222/" + fileRef);
giving error
Invalid URI: The format of the URI could not be determined.
Can anyone please suggest me how to do this.