0

I have the following code:

public void ChangeFolderPermission()
{
    SP.ClientContext ctx = new SP.ClientContext("https://sharepoint.oshirowanen.com/sites/oshirodev/");
    ctx.Credentials = new NetworkCredential("user", "pass", "domain");

    SP.Principal user = ctx.Web.EnsureUser("accountName");
    var folder = ctx.Web.GetFolderByServerRelativeUrl("folderUrl");
    var roleDefinition = ctx.Site.RootWeb.RoleDefinitions.GetByType(SP.RoleType.Reader);  //get Reader role
    var roleBindings = new SP.RoleDefinitionBindingCollection(ctx) { roleDefinition };
    folder.ListItemAllFields.BreakRoleInheritance(true, false);  //set folder unique permissions
    folder.ListItemAllFields.RoleAssignments.Add(user, roleBindings);
    ctx.ExecuteQuery();  
}

but the following lines:

folder.ListItemAllFields.BreakRoleInheritance(true, false);  //set folder unique permissions
folder.ListItemAllFields.RoleAssignments.Add(user, roleBindings);

gives this error message:

'Microsoft.SharePoint.Client.Folder' does not contain a definition for 'ListItemAllFields' and no extension method 'ListItemAllFields' accepting a first argument of type 'Microsoft.SharePoint.Client.Folder' could be found (are you missing a using directive or an assembly reference?)

I have the following project references

Microsoft.SharePoint.Client
microsoft.SharePoint.Client.Runtime

I have the following using directive

using SP = Microsoft.SharePoint.Client;

Any idea why I am getting this error?

The application is a winform which runs from a desktop environment.

oshirowanen
  • 15,297
  • 82
  • 198
  • 350
  • Stupid question on my part, but don't you have to use SP.folder when defining the folder object or is the compiler smart enough to know the return type based on the function you called. – Eric May 10 '17 at 11:56

1 Answers1

1

This is because SharePoint 2010 Folder API does not have "ListItemAllFields" property - it was added in 2013.

Possible duplicate of: field or property \"ListItemAllFields\" does not exist exception

Community
  • 1
  • 1
Nikolay
  • 10,752
  • 2
  • 23
  • 51