0

I have the following code inside my server-side ER, to get a file and added inside another folder :-

byte[] fileBytes = softemplete.File.OpenBinary();
SPFile destFile = currentDL.RootFolder.Files.Add(destUrl, fileBytes, false);

and i want to change the code to CSOM, so i define the following

var fileBytes = softemplete.File.OpenBinaryStream();
FileCreationInformation fci = new FileCreationInformation();
fci.Overwrite = false;
fci.Url = destUrl;
fci.ContentStream = fileBytes;
Microsoft.SharePoint.Client.File destFile = currentDL.RootFolder.Files.Add(fci);

but i am getting this error Cannot implicitly convert type 'Microsoft.SharePoint.Client.ClientResult<System.IO.Stream>' to 'System.IO.Stream' on fci.ContentStream = fileBytes;.. any advice?

1

FileCreationInformation.ContentStream property is basically of type System.IO.Stream, whereas, File.OpenBinaryStream method returns Microsoft.SharePoint.Client.ClientResult type.

Check this post from Microsoft for different ways of uploading files to SharePoint and use the one best suited for your need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.