Unable to use SaveBinaryDirect with Sharepoint online always return 403

Viewed 5602

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");
      ctx.Load(lib);
      ctx.Load(lib.RootFolder);
      ctx.ExecuteQuery();
      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.

https://razirais.wordpress.com/2011/05/19/how-to-fix-sharepoint-online-403-forbidden-error-while-downloading-files-using-client-object-model/

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 ?

1 Answers
Related