question

10031103-4153 avatar image
0 Votes"
10031103-4153 asked ·

Alternative Save/OpenBinaryDirect methods for CSOM for SharePoint Online

Based on the doc from MS
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
12469-csom.png



So for .NET core app, what is the alternative way to read/write files stored in SharePoint online? what is the regular file API? does anyone done this? any example code/documentation?

office-sharepoint-online
csom.png (39.3 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
2 Votes"
MichaelHan-MSFT answered ·

You could use the file.OpenBinaryStream() to read/write files stored in SharePoint, below is my demo code for your reference:

         Microsoft.SharePoint.Client.File file = context.Web.GetFileByUrl("https://tenant.sharepoint.com/sites/michael/Shared%20Documents/aa.txt");
         context.Load(file);
         context.ExecuteQuery();       
     
         Microsoft.SharePoint.Client.ClientResult<Stream> mstream = file.OpenBinaryStream();
         context.ExecuteQuery();
            
         using (System.IO.StreamReader sr = new System.IO.StreamReader(mstream.Value))
         {
           String line = sr.ReadToEnd();
           Console.WriteLine(line);
         }



· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Very useful! Thank you!

But I would like to know how to upload a (local) file to a Folder.

The key is before the BinaryWriter, but I couldn't figure out.

Can you help me?

0 Votes 0 ·

Hi @FabioBrandao ,

For your new question, I would suggest you ask a new question in the forum.

0 Votes 0 ·
Grmacjon-MSFT avatar image
0 Votes"
Grmacjon-MSFT answered ·

Hi @10031103-4153,

Welcome to Microsoft Q&A! Currently, Microsoft Q&A supports the products listed over here (more to be added later on).

Your question about Alternative Save/OpenBinaryDirect methods for CSOM for SharePoint Online is not yet supported on this platform. You could ask about this in the SharePoint Developers forums:https://techcommunity.microsoft.com/t5/sharepoint-developer/bd-p/SharePointDev


Thanks,

Grace


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

trevorseward avatar image
0 Votes"
trevorseward answered ·

.NET Standard CSOM is now available as of June 23rd on NuGet. You should be able to use this CSOM binary with your .NET Core app.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Unfortunately, MS drop some features, including this one, you can check this video: https://youtu.be/mb6OEDOhVW4, @ 2:35

0 Votes 0 ·