For SharePoint Online, I am trying to get user permissions on a site, including library, folders and files, using CSOM.
I have the following code:
ClientResult<BasePermissions> info = site.Web.GetUserEffectivePermissions(user.LoginName);
and well I have two problems, first, info
is null.
Second, I cannot use info.RoleAssignments
Visual Studio gives me the error:
Error 1 'Microsoft.SharePoint.Client.ClientResult' does not contain a definition for 'RoleAssignments' and no extension method 'RoleAssignments' accepting a first argument of type 'Microsoft.SharePoint.Client.ClientResult' could be found (are you missing a using directive or an assembly reference?)
I read that when you are using SharePoint dll you may have used the wrong one, but I am using SharePoint.Client so, any ideas?
This is the first part of the code:
using (ClientContext site = new ClientContext(siteTextBox.Text))
{
SecureString password = new SecureString();
foreach (char c in "mypass".ToCharArray()) passWord.AppendChar(c);
site.Credentials = new SharePointOnlineCredentials("[email protected]", password);
site.Load(site.Web);
site.ExecuteQuery();
Web web = site.Web;
User user = web.EnsureUser(userTextBox.Text); //string is like: [email protected] on userTextBox
site.Load(user);
site.ExecuteQuery();
ClientResult<BasePermissions> info = site.Web.GetUserEffectivePermissions(user.LoginName);
//info.RoleAssignments is not recognized
foreach (SPRoleAssignment roleAssignment in info.RoleAssignments)
{
//Do something
}
}