仅删除包含特定字符的SPGroup

时间:2014-10-27 15:46:19

标签: c# sharepoint-2010

我需要从SharePoint网站中删除名称中包含下划线的组。我需要类似下面的代码,但我无法在collGroups上使用.Contains。

知道我该怎么做吗?

 using (SPSite oSite = new SPSite(spsite))
 {
    using (SPWeb oWeb = oSite.OpenWeb())
    {         
        SPGroupCollection collGroups = oWeb.SiteGroups;  
        if(collGroups.Contains("_"))  //this doens't work, but I need something like this
        {
            group.Delete();
        }
    }
 }

1 个答案:

答案 0 :(得分:0)

供将来参考:这是我写完的内容,感谢gunr2171让我指向正确的方向!

  using (SPSite oSite = new SPSite(spsite))
  {
       using (SPWeb oWeb = oSite.OpenWeb())
       {
            var result = (from g in oWeb.Groups.OfType<SPGroup>()
                          where g.Name.Contains("_")
                          select g).ToList();

            foreach (SPGroup group in result)
            {
                SPGroupCollection collGroups = oWeb.SiteGroups;
                collGroups.Remove(group.Name);
                Console.WriteLine("Removed " + group.Name);
             }

             Console.WriteLine("Process Complete!");
        }
相关问题