深入浅出SharePoint——Group的常用操作

删除群组

错误的做法

foreach (SPGroup group in web.SiteGroups)
{
    if (group.Name.ToLower() == grpName.ToLower())
    {
        web.SiteGroups.Remove(grpName);
     }
}                                

原因:当我们增加或删除集合中的条目(Item)时候,Enumerator枚举不知道数据集合中有多少个条目(Item)。

正确的做法:

for (int index = 0; index <= web.SiteGroups.Count - 1; index++)
{
    if (web.SiteGroups[index].Name.ToLower() == grpName.ToLower())
    {
        web.SiteGroups.Remove(grpName);
    }
}

 

posted @ 2013-01-10 13:31  风影极光  阅读(374)  评论(0编辑  收藏  举报