Is it possible to retrieve the list of users who have access to a folder in Sharepoint via folder name instead of folder ID?

Reason: The folder is from a subsite, and have another unique id as compared to the main site, so user list will be empty or inaccurate due to different id in main and sub sites.

Current code:


//to modify the following code to get by folder name, instead of folder id 
node.Attributes.Add("access", GetAccessXml(folder.Item.RoleAssignments, out originalAccess));


private string GetAccessXml(SPRoleAssignmentCollection roleAssignments, out string originalAccess)
    //currently returning empty list
    var list = roleAssignments.GetUserWithReadPermissionOnly();

    var entries = "<Entities Append=\"False\" Error=\"\" Separator=\";\" MaxHeight=\"3\">{0}</Entities>";
    var entryTemplate = "<Entity Key=\"{0}\" DisplayText=\"{1}\" IsResolved=\"True\" Description=\"{0}\"><MultipleMatches /></Entity>";
    var entryBuilder = new StringBuilder();
    var csv = new StringBuilder();

    foreach (var principal in list)
        var entry = entryTemplate;
        entryBuilder.AppendFormat(entry, principal.LoginName, principal.Name);
    originalAccess = csv.ToString().TrimEnd(',');
    return entries.FormatWith(entryBuilder);

I am thinking of the using folder.Item.Title or folder.Item.Name but they do not have .RoleAssignments implementation.

Any help will be appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.