删除群组

错误的做法

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);
    }
}

 

相关文章:

  • 2021-07-25
  • 2021-10-15
  • 2021-11-02
  • 2022-02-11
  • 2021-10-28
  • 2021-12-18
  • 2022-02-23
  • 2021-07-29
猜你喜欢
  • 2021-11-21
  • 2021-12-27
  • 2021-05-21
  • 2022-01-15
  • 2021-06-21
  • 2021-05-20
相关资源
相似解决方案