Inorder to know if a particular group exists in sharepoint group collection , just use the following function..
private bool GroupExists(SPGroupCollection objgroups, string strName)
{
const string NAME = "Name";
bool isGroupExists = false;
if (string.IsNullOrEmpty(strName) ||
(strName.Length > 255) ||
(objgroups == null) ||
(objgroups.Count == 0))
{
isGroupExists = false;
}
else
{
XDocument doc = XDocument.Parse(objgroups.Xml);
isGroupExists = doc.Descendants().Where(g => g.Attribute(NAME) != null).Where(g => g.Attribute(NAME).Value.Equals(strName, StringComparison.InvariantCultureIgnoreCase)).Count() > 0;
}
return isGroupExists;
}
The function would return true if the group exists in group collection of sharepoint..
You just have to call the function as shown below :
SPGroupCollection objSiteGroups = YOURWEBOBJECT.SiteGroups;
if (GroupExists(objSiteGroups, "YOUR GROUP NAME"))
{
// Do all that you want with the group coz the group does exists
}
Happy sharepointing :)
private bool GroupExists(SPGroupCollection objgroups, string strName)
{
const string NAME = "Name";
bool isGroupExists = false;
if (string.IsNullOrEmpty(strName) ||
(strName.Length > 255) ||
(objgroups == null) ||
(objgroups.Count == 0))
{
isGroupExists = false;
}
else
{
XDocument doc = XDocument.Parse(objgroups.Xml);
isGroupExists = doc.Descendants().Where(g => g.Attribute(NAME) != null).Where(g => g.Attribute(NAME).Value.Equals(strName, StringComparison.InvariantCultureIgnoreCase)).Count() > 0;
}
return isGroupExists;
}
The function would return true if the group exists in group collection of sharepoint..
You just have to call the function as shown below :
SPGroupCollection objSiteGroups = YOURWEBOBJECT.SiteGroups;
if (GroupExists(objSiteGroups, "YOUR GROUP NAME"))
{
// Do all that you want with the group coz the group does exists
}
Happy sharepointing :)
No comments:
Post a Comment