我需要从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();
}
}
}
答案 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!");
}