I need to get the visitor group name of the SharePoint site in c#.please suggest any idea?


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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.