views:

1396

answers:

0

Hi,

I need to add permission levels to a list like: Full Control, Contribute, Manage Hierarchy, view Only, etc. I see here: "programatically add user permission to a list in sharepoint", that this can be done using the Object Model. How would I do the same using Web Services?

I tried using the permissions.asmx web services, it works for some of them giving the correct mask like 1011028991 for Approve, 138612833 for read, but it doesn't work for others like Manage Hierarchy, Restricted Read, and any other user created role (permission level). Instead of the correct name I get: Auto-generated Permission Level edda2384-2672-4e24-8f31-071d61a8c303

Any help will be appreciated.


OK, here is a code example, to obtain the mask I based this code on the one from this forum.

string sPermissionName = "Manage Hierarchy"; // if I use Read, Approve, Contribute, Full Control, it works!
string sListName = "testList";
string sGroupName = string.Format("{0}_ManageHierarchy", sListName);

// Create an aux group just to obtain the mask number later
using (SPUserGroup.UserGroup ug = new SPUserGroup.UserGroup())
{
    ug.Credentials = new NetworkCredential("user", "pasword");
    ug.Url = "http://testSite/_vti_bin/UserGroup.asmx";
    ug.AddGroup(sGroupName, "testDomain\\user", "user", "testDomain\\user", "Manage Hierarchy test");
    ug.AddGroupToRole(sPermissionName, sGroupName);
}

using (SPPermissions.Permissions per = new SPPermissions.Permissions())
{
    per.Credentials = new NetworkCredential("user", "password");
    per.Url = "http://testSite/_vti_bin/Permissions.asmx";

    XmlNode perms = per.GetPermissionCollection(sListName, "list");
    XmlNode n = perms.SelectSingleNode(string.Format("/*[local-name()='Permissions']/*[local-name()='Permission' " +
        "and @MemberIsUser='False' and @GroupName='{0}']", sGroupName));

    // Here we get the Mask for the role
    int iMask = int.Parse(n.Attributes["Mask"].Value);
    Console.WriteLine("The mask is:{0}", iMask); // Just to see the mask, I get 2129075183 for Manage Hierarchy

    // Here I want to add some user to the list with the specified permission level
    // But I get for example: Auto-generated Permission Level edda2384-2672-4e24-8f31-071d61a8c303 
    // Also, If later I execute the GetPermissionCollection, I see that the mask they got is: 2129075199  and not what I passed which was: 2129075183 
    per.AddPermission(sListName, "list", "testDomain\\user01", "user", iMask);
    per.AddPermission(sListName, "list", "testDomain\\user02", "user", iMask);
}