I need to get the visitor group name of the SharePoint site in c#.please suggest any idea?
2
Try below code:
SPWeb web = SPContext.Current.Web;
Group visitorGroup = web.AssociatedVisitorGroup;
You can also try below method:
int idOfGroup = Convert.ToInt32(web.Properties["vti_associatevisitorgroup"]);
SPGroup group = web.SiteGroups.GetByID(idOfGroup);
Or iterating through the site groups as below:
public static SPGroup GetVisitorsGroup(SPWeb web)
{
if (web.Properties["vti_associatevisitorgroup"] != null)
{
string idOfVisitorGroup = web.Properties["vti_associatevisitorgroup"];
int visitorGroupId = Convert.ToInt32(idOfVisitorGroup);
foreach (SPGroup group in web.SiteGroups)
{
if (group.ID == visitorGroupId)
{
return group;
}
}
}
return null;
}
Reference - Get visitor group