获取 SharePoint 中的所有网站、列表和用户权限

发布于 2024-08-20 23:30:53 字数 79 浏览 2 评论 0原文

是否可以使用代码获取 SharePoint 中的所有网站名称?具体来说,是否可以列出每个站点的所有列表名称,并列出所有用户及其对列表的访问权限?

Is it possible using code to get all the names of the sites in SharePoint? Specifically, is it possible to list all the names of the lists for each site, and list all the users and their access to the lists?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2024-08-27 23:30:54

快速,肮脏,只进行了一些测试,但它应该可以工作。将 Web 应用程序 URL 替换为您自己的 URL:

 static void ListLists()
        {
            SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://mossdev:8060"));
            foreach(SPSite site in webApp.Sites)
            {
                try
                {
                    PrintWebAndListsRecursive(site.RootWeb, 0);
                }
                finally
                {
                    site.Dispose();
                }
            }

            Console.ReadLine();
        }

        static void PrintWebAndListsRecursive(SPWeb web, int level)
        {
            Console.WriteLine("".PadLeft(level * 3) + "Site: {0} ({1})", web.Title, web.Url);
            foreach(SPList list in web.Lists)
            {
                Console.WriteLine("".PadLeft((level + 1) * 3) + "List: {0}", list.Title);
                foreach(SPRoleAssignment roleAssignment in list.RoleAssignments)
                {                    
                    if(roleAssignment.Member is SPGroup)
                    {
                        var group = (SPGroup) roleAssignment.Member;
                        Console.WriteLine("".PadLeft((level + 2) * 3) + "Group: {0}", group.Name);   
                        foreach(SPUser user in group.Users)
                        {
                            Console.WriteLine("".PadLeft((level + 4) * 3) + user.Name);   
                        }
                    }
                    else
                    {
                         Console.WriteLine("".PadLeft((level + 2) *3) + "User: {0}", roleAssignment.Member.Name);  
                    }

                    foreach(SPRoleDefinition roleDef in roleAssignment.RoleDefinitionBindings)
                    {
                        if (!roleDef.Hidden)
                        {
                            Console.WriteLine("".PadLeft((level + 3) * 3) + "Role Definition: {0}", roleDef.Name);
                        }
                    }
                }
            }

            foreach(SPWeb subWeb in web.Webs)
            {
                try
                {
                    PrintWebAndListsRecursive(subWeb, level+1);
                }
                finally
                {
                    subWeb.Dispose();
                }
            }
        }

Quick, dirty, only somewhat tested but it oughtta work. Replace the web application URL with your own:

 static void ListLists()
        {
            SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://mossdev:8060"));
            foreach(SPSite site in webApp.Sites)
            {
                try
                {
                    PrintWebAndListsRecursive(site.RootWeb, 0);
                }
                finally
                {
                    site.Dispose();
                }
            }

            Console.ReadLine();
        }

        static void PrintWebAndListsRecursive(SPWeb web, int level)
        {
            Console.WriteLine("".PadLeft(level * 3) + "Site: {0} ({1})", web.Title, web.Url);
            foreach(SPList list in web.Lists)
            {
                Console.WriteLine("".PadLeft((level + 1) * 3) + "List: {0}", list.Title);
                foreach(SPRoleAssignment roleAssignment in list.RoleAssignments)
                {                    
                    if(roleAssignment.Member is SPGroup)
                    {
                        var group = (SPGroup) roleAssignment.Member;
                        Console.WriteLine("".PadLeft((level + 2) * 3) + "Group: {0}", group.Name);   
                        foreach(SPUser user in group.Users)
                        {
                            Console.WriteLine("".PadLeft((level + 4) * 3) + user.Name);   
                        }
                    }
                    else
                    {
                         Console.WriteLine("".PadLeft((level + 2) *3) + "User: {0}", roleAssignment.Member.Name);  
                    }

                    foreach(SPRoleDefinition roleDef in roleAssignment.RoleDefinitionBindings)
                    {
                        if (!roleDef.Hidden)
                        {
                            Console.WriteLine("".PadLeft((level + 3) * 3) + "Role Definition: {0}", roleDef.Name);
                        }
                    }
                }
            }

            foreach(SPWeb subWeb in web.Webs)
            {
                try
                {
                    PrintWebAndListsRecursive(subWeb, level+1);
                }
                finally
                {
                    subWeb.Dispose();
                }
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文