Unable to use SaveBinaryDirect with Sharepoint online always return 403


Staff member
i am new with SharePoint,

I am trying to upload a picture inside a document library by c# code.

There is my code

string webUrl = "https://mysharepointesite.sharepoint.com/";

  string targetSite = webUrl;
  using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite))
    if (ctx != null)
      var lib = ctx.Web.Lists.GetByTitle("mesdocuments");
      string sourceUrl = "C:\\temp\\picture.jpg";          
      using (FileStream fs = new FileStream(sourceUrl, FileMode.Open, FileAccess.Read))
        Microsoft.SharePoint.Client.File.SaveBinaryDirect (ctx, lib.RootFolder.ServerRelativeUrl + "/myPicture.jpg", fs, true);

But i always get an 403 error.

I also verify if it was not the same issue has mentionned in this post, but i don't think it is.

<a href="https://razirais.wordpress.com/2011...-downloading-files-using-client-object-model/" rel="nofollow noreferrer">https://razirais.wordpress.com/2011...-downloading-files-using-client-object-model/</a>

When i do it i received a 405 error, and the fiddler log show me that the request was trying to redirect the context to the authentication page.

it's there a setting i need to enable ? Any idea what is my trouble ?