1
votes

I have a scenario in my custom visual web part where I need to check for logged in User is a member of sharepoint group(sharepoint groups or users are stored in a sharepoint list). Actually if logged in users exists in the list, he will be given Edit access in my custom web part.

Since I have created a group name "SharePoint_Owners" with group settings as 'Who can View Membership of this group' to 'Group Members', Site is throwing error as 'Access denied' as logged in user doesn't have permission to view. I get error when my code executes this, SPGroup oGroup = oWebsite.SiteGroups[strgroup];///strgroup is a group name foreach (SPUser oUser in oGroup.Users) { }

Site throws this error when I try to open page which consists my webpart.

Can any one suggest me how do i proceed? is there a way to resolve this programmatically without actually giving View permission to "Everyone" for each group?? I thought RunWithElevatedPrivileges does my work but have no luck!

please help

1

1 Answers

0
votes

Try this:

SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                string siteURL = SPContext.Current.Site.Url;
                using (SPSite safeSite = new SPSite(siteURL))
                {
                    using (SPWeb safeWeb = safeSite.OpenWeb())
                    {
                        SPGroup group = safeWeb.Groups["SharePoint_Owners"];
                        bool isMember = safeWeb.IsCurrentUserMemberOfGroup(group.ID);                       
                    }
                }
            });