Search code examples
c#-4.0sharepoint-2010.net-4.0csom

Does not contain a definition for ListItemAllFields


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.


Solution

  • 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