Not Able to share a file using Microsoft.sharepoint.client

Copper Contributor

Hi,

I am sharing a file problematically to some users using Microsoft.SharePoint.Client. Its showing file are shared with users successfully and have label like its shared with users. But receivers do not receive any file from their shared with me folder.

I tried Microsoft.SharePoint.Client code to share file

ClientContext ctx = new ClientContext("My onedrive URL");
ctx
.Credentials = new SharePointOnlineCredentials(username, passWord);
Principal user = ctx.Web.EnsureUser(username);
Principal user = ctx.Web.EnsureUser("Onedrive User");
var roleDefinition = ctx.Site.RootWeb.RoleDefinitions.GetByType(RoleType.Reader); 
var roleBindings = new RoleDefinitionBindingCollection(ctx) { roleDefinition };
folder
.ListItemAllFields.RoleAssignments.Add(user, roleBindings);                       
ctx
.Load(folder);
ctx
.ExecuteQuery();

Let me know why files were not shared with users in their "shared with me" ?

Note: But I can able to view the files bucket "Our File". But its not good to share via this. 

 

0 Replies