代码之家  ›  专栏  ›  技术社区  ›  Magnus Johansson

如何以编程方式确定SharePoint中网站的3个权限组访问者/成员/所有者?

  •  4
  • Magnus Johansson  · 技术社区  · 16 年前

    在SharePoint中,我们有3个预先确定的权限组:

    • 来访者
    • 成员
    • 业主

    作为/_layouts/permsetup.aspx页面中的设置。

    (网站设置->人员和组->设置->设置组)

    如何以编程方式获取这些组名?

    (页面逻辑被微软弄糊涂了,所以在Reflector中无法执行)

    3 回复  |  直到 16 年前
        1
  •  11
  •   Alex Angas Colin    16 年前

    SPWeb类上有以下属性:

    • SPWeb.AssociatedVisitorGroup
    • SPWeb.AssociatedMemberGroup

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.associatedmembergroup.aspx

        2
  •  5
  •   Community Mohan Dere    9 年前

    我发现各种“关联…”属性通常为空。唯一可靠的方法是在SPWeb上使用属性包:

    • 访客: vti_associatevisitorgroup
    • vti_associatemembergroup
    • 业主: vti_associateownergroup

    要将它们转换为SPGroup对象,可以使用:

    int idOfGroup = Convert.ToInt32(web.Properties["vti_associatemembergroup"]);
    SPGroup group = web.SiteGroups.GetByID(idOfGroup);
    

    然而 Kevin mentions ,关联可能会丢失,这将在上述代码中引发异常。更好的方法是:

    1. 通过确保您要查找的属性实际存在,检查是否在web上设置了关联。

    2. 检查属性给定ID的组是否实际存在。删除对SiteGroups.GetByID的调用,而是在SiteGroups中的每个SPGroup中循环查找ID。

    public static SPGroup GetMembersGroup(SPWeb web)
    {
        if (web.Properties["vti_associatemembergroup"] != null)
        {
            string idOfMemberGroup = web.Properties["vti_associatemembergroup"];
            int memberGroupId = Convert.ToInt32(idOfMemberGroup);
    
            foreach (SPGroup group in web.SiteGroups)
            {
                if (group.ID == memberGroupId)
                {
                    return group;
                }
            }
        }
        return null;
    }
    
        3
  •  4
  •   Kevin Davis    16 年前

    你好,我是凯文,我是微软SharePoint权限的PM。

    DJ的回答是完全正确的,但我要警告你,根据你所做的,这可能不是最可靠的方法。用户可能会将这些组吹走,而这些关联也会消失。我肯定会在你获取这些东西的过程中建立一些备份逻辑。