Alternative Save/OpenBinaryDirect methods for CSOM for SharePoint Online

10031103 41 Reputation points
2020-07-15T13:18:12.877+00:00

Based on the doc from MS
https://learn.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?

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,126 Reputation points
    2020-07-16T08:31:24.78+00:00

    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);
            }
    
    5 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Grmacjon-MSFT 19,301 Reputation points Moderator
    2020-07-15T21:43:05.37+00:00

    Hi @10031103 ,

    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

    0 comments No comments

  2. trevorseward 11,711 Reputation points
    2020-07-16T03:38:06.333+00:00

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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.