简体   繁体   English

以编程方式获取特定用户的所有SharePoint文件夹权限

[英]Get all SharePoint folder permissions of a particular user programatically

I am trying to access permissions of all folders(not hidden) in a site for a particular user 我正在尝试为特定用户访问网站中所有文件夹(未隐藏)的权限

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
             {
                 SPWeb web = site.OpenWeb();
                 SPFolderCollection folders = web.Folders;;
                 foreach (SPFolder folder in web.Folders)
                 {


                     lblFolder.Text += "<br/><STRONG>" + folder.Name + "</STRONG>

<br/>";
 foreach (SPRoleAssignment folderRole in folder.Item.RoleAssignments)
                         { }// throws exception object specifies does not belong to list



                 }

Not only name but i need the permissions on that folder, please help!! 不仅名称,而且我需要该文件夹的权限,请帮助!!

Thanks 谢谢

You're grabbing folders when maybe you should be grabbing the list items of the document library? 您正在抓取文件夹时,也许您应该抓取文档库的列表项? That is, assuming they inherit from the top. 也就是说,假设它们从顶部继承。

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["Documents"];
        SPQuery qry = new SPQuery();
        qry.Query = "<Where><Eq><FieldRef Name='Title'><Value Type='Text'>"+title+"</Value></Eq></Where>";
        SPListItemCollection docColl = new SPListItemCollection(qry);
        List<string> perms = new List<string>();

        if (docColl.Count > 0)
        {
            SPListItem fldrItem = docColl[0];
            if (fldrItem.RoleAssignments.Count > 0) {

                SPRoleAssignmentCollection assignColl = fldrItem.RoleAssignments;
                foreach (SPRoleAssignment assignment in assignColl)
                {
                    perms.Add(assignment.Member.LoginName);
                    Console.WriteLine("Perms: " + assignment.Member.LoginName);
                }
            }
        }
    }
}

SPWeb.Folders gives you a collection of the "sub folders" of your web site (Like _catalogs, Lists, ...) none of these have an associated List Item, some of them like Shared Documents may have an associated list, but in that case they are the root folder which doesn't have a list item (the rights come directly from the list). SPWeb.Folders为您提供了网站的“子文件夹”的集合(如_catalogs,List等),它们都不具有关联的列表项,其中一些诸如“共享文档”可能具有关联的列表,但是在在这种情况下,它们是没有列表项的根文件夹(权限直接来自列表)。

So you should check if Item is null (Maybe in that case use ParentListId to get the List if it's not Guid.Empty) and then continue by parsing SubFolders recursively 因此,您应该检查Item是否为null(在这种情况下,如果不是Guid.Empty,则可以使用ParentListId获取List),然后继续递归解析SubFolders

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式使用C#为所有用户和组显示文件夹的权限 - Displaying permissions of a folder for all users and groups using C# Programatically SharePoint 2010客户端对象模型以编程方式将Sharepoint用户/组添加到每个文档库文件夹 - SharePoint 2010 Client Object Model Add Sharepoint user/group to every document library folder programatically 检查特定用户是否以编程方式访问sharepoint(C#代码) - Check whether a particular user has access to sharepoint programatically (C# code) 无法在Sharepoint中以编程方式访问共享文件夹 - Cannot access shared folder programatically in sharepoint 如何以编程方式在Sharepoint站点上创建文件夹 - How to programatically create a folder at a Sharepoint site Sharepoint Provider托管用户权限 - Sharepoint Provider Hosted User Permissions 以编程方式获取 Windows 2003 中文件夹的组-用户-权限-特殊权限列表 - Get list of groups-users-permissions-special permission for a folder in Windows 2003, programatically 检查用户是否有权使用 PnP Core 将文件上传到 SharePoint 文件夹 - Check if user has permissions to upload file to SharePoint folder using PnP Core 以编程方式阻止在特定文件夹中创建文件 - Block creating a file in a particular folder programatically 如何获取特定用户的所有 AD 组? - How to get all the AD groups for a particular user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM