当前用户属于sharepoint中的特定组?

时间:2012-02-23 07:08:30

标签: sharepoint-2010

我创建了一个代码来查找当前登录用户属于某个特定组但是我收到错误消息

  

IsCurrentUserMemberOfGroup(gName1);包含一些无效的参数。

请帮帮忙?

这是我的代码

SPSite oSite = (SPSite)properties.OpenWeb().Site;
SPWeb oWeb = oSite.OpenWeb();
SPGroupCollection myGroup = oWeb.Groups;
foreach (SPGroup gName in myGroup)
{
    //string gname1 = gName.ToString();
    SPGroup gName1 = gName;
    if (gName1.Name == "Final Approval Group")
    {
        //SPGroup lGroup = oWeb.Groups["Final Approval Group"];
        bool answer = oWeb.IsCurrentUserMemberOfGroup(gName1);
        fValue = 1;
        break;
    }
}

1 个答案:

答案 0 :(得分:0)

尝试使用gName1.ID,因为IsCurrentUserMemberOfGroup采用int参数。

SPGroupCollection myGroup = oWeb.Groups; 
  foreach (SPGroup gName in myGroup) { 
    //string gname1 = gName.ToString(); 
    SPGroup gName1 = gName; 
    if (gName1.Name == "Final Approval Group") { 
      //SPGroup lGroup = oWeb.Groups["Final Approval Group"]; 
      bool answer = oWeb.IsCurrentUserMemberOfGroup(gName1.ID); 
      fValue = 1; break; 
  } 
}