Saturday, November 26, 2011

Check Current User Gorup In SharePoint Object Model


To manage permission we create Groups in SharePoint. In Custom SharePoint application or webpart, we have to check user permissions or may have activate different  functionality.

For that We need to check Current User Group..

Here is a function that will return true/false by providing Group Name!

private bool IsCurrentUserMemberOfGroup(string GroupName)
        {
            try
            {
              return SPContext.Current.Web.IsCurrentUserMemberOfGroup(SPContext.Current.Web.Groups[GroupName].ID);               
            }
            catch (Exception)
            {
                return false;
            }
        }


You may provide web object for performance tuning.

1 comment: