Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Button Visibility based on user availability in the group

$
0
0

Hi,

I am displaying a folder if logged in user is not available in one of the SharePoint group called TestGroup.

For this I have written the code as below

But the problem is button is getting displayed to users who are in the TestGroup.

Please let me know if I am missing anything here.

privatevoid DisplayCreateSubFolder()

        {

           bool isMember = false;

           SPSecurity.RunWithElevatedPrivileges(delegate

            {

               using (SPSite site =newSPSite(SPContext.Current.Site.Url))

                {

                   SPWeb web = site.RootWeb;

                   string groupName = "TestGroup";

                   var spGroup = web.Groups[groupName];

                    isMember = web.IsCurrentUserMemberOfGroup(spGroup.ID);

                   if (isMember == true)

                    {

                        btn_CreateFolder_display.Visible =false;

                    }

                   else

                    {

                        btn_CreateFolder_display.Visible =true;

                    }

                }

            });    

        }

In the Page Load method I am calling the method as below

protectedvoid Page_Load(object sender,EventArgs e)

        {

           try

            {

               

                DisplayCreateSubFolder();

            }

           catch (Exception ex)

            {

                Response.Write(ex.ToString());

            }

        }

 Regards,

Sudheer


Thanks & Regards, Sudheer


Viewing all articles
Browse latest Browse all 11571


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>