Alternative Save/WriteBinaryDirect methods for CSOM for SharePoint Online

Fabio Brandão 6 Reputation points

Based on the doc from MS


So for .NET core app, what is the alternative way to upload files to a Document Library on SharePoint Online?
What is the regular file API?
Does anyone done this?
Any example code/documentation?

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,275 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,021 Reputation points

    Hi @Fabio Brandão ,

    Below is my sample code to upload files to document library, hope it helps you:

        string filepath = @"C:\temp\test.txt" ;  
        FileCreationInformation newfile = new FileCreationInformation();  
        byte[] FileContent = System.IO.File.ReadAllBytes(filepath);  
        newfile.ContentStream = new MemoryStream(FileContent);  
        newfile.Url = "test.txt";  
        Folder library = context.Web.GetFolderByServerRelativeUrl("/sites/michael/Shared%20Documents");  
        Microsoft.SharePoint.Client.File uploadfile = library.Files.Add(newfile);  

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.