Skip to main content

Hello

 

I created Service broker to connect to SharePoint Online, that contain  GetDocument method.  to set the value i used this format:

 

 string.Format("<file><name>{0}</name><content>{1}</content></file>",fileName,content, GetDocumentAsString(context,listTitle,id));

 

the GetDocumentAsString(ClientContext clientContext, string ListTitle, int ItemID)

{

 

Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();

List spList = web.Lists.GetByTitle(ListTitle);

File readFile = spList.GetItemById(ItemID).File;

clientContext.Load(readFile);
clientContext.ExecuteQuery();


var fileRef = readFile.ServerRelativeUrl;
var fileInfo = File.OpenBinaryDirect(clientContext, fileRef);

var fileName = readFile.Name;
var fileContentStream = new System.IO.MemoryStream();

 

fileInfo.Stream.CopyTo(fileContentStream);

 


byte8] bytes = new byte fileContentStream.Length];
fileInfo.Stream.Read(bytes, 0, (int)fileContentStream.Length);
return Convert.ToBase64String(bytes, 0, (int)fileContentStream.Length, Base64FormattingOptions.None);

 

}

 

the code works but the file is corrupted.. I think i have a problem with encoding

someone have any idea how to create property from type File? what is the correct format of the value ?

 

 

How you are passing on login and password

how you are using oauth token in broker code can you share some sample code how to create clientcontext using oauth token and  oauth  resource type?


Reply