Tuesday, January 6, 2015

How to Check Group Exists in SharePoint Programatically

I was trying to check if specific group exists in SharePoint web. I couldn't find any OTB API method to achieve this.
Hence I am using the below LINQ statement to check whether group exists in a web.
string groupName = "MyGroupName";
SPWeb web = SPContext.Current.Web;
 //Check if group exists in the web
 if (web.Groups.OfType<SPGroup>().Count(g=>g.Name.Equals(groupName, StringComparison.InvariantCultureIgnoreCase))>0)
 {
     //Get the SPGroup by group name if exists
     SPGroup group = web.Groups[groupName];
 }

1 comment:

  1. https://social.msdn.microsoft.com/Forums/sharepoint/en-US/8af0e687-b3ac-4d0d-a864-6dcf3816a44c/checking-if-group-exists?forum=sharepointdevelopmentlegacy

    ReplyDelete