Take InfoPath form data in XML and upload it into other Document Library

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.

  1. FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef.ToString()); gives 401 unauthorized error
  2. 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.

  1. 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.

Replay

Category: sharepoint online Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.757 (s). 13 q(s)