c# - Only Remove SPGroups that Contain a specific Character -
i need remove groups sharepoint site contain underscore in name. need below code, unable utilize .contains on collgroups.
any thought how can this?
using (spsite osite = new spsite(spsite)) { using (spweb oweb = osite.openweb()) { spgroupcollection collgroups = oweb.sitegroups; if(collgroups.contains("_")) //this doens't work, need { group.delete(); } } }
for future reference: here ended writing, gunr2171 pointing me in right direction!
using (spsite osite = new spsite(spsite)) { using (spweb oweb = osite.openweb()) { var result = (from g in oweb.groups.oftype<spgroup>() g.name.contains("_") select g).tolist(); foreach (spgroup grouping in result) { spgroupcollection collgroups = oweb.sitegroups; collgroups.remove(group.name); console.writeline("removed " + group.name); } console.writeline("process complete!"); }
c# sharepoint-2010
No comments:
Post a Comment