Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.
Showing posts with label SharePoint Groups Code. Show all posts
Showing posts with label SharePoint Groups Code. Show all posts

Tuesday, December 06, 2011

Doing Some Operation If User is Having Admin Priviledges to the Site...!

 try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWeb currentWeb = SPContext.Current.Web;
                    if (currentWeb.CurrentUser.IsSiteAdmin)
                    {
                        writer.Write("Logged User is Having Admin Permissions to the Site...!");
                    }

                });
            }
            catch (Exception ex)
            {
                writer.Write(ex.ToString());
            }

Getting the Group of the Currently Logged User

try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWeb currentWeb = SPContext.Current.Web;
                    foreach (SPGroup grp in currentWeb.CurrentUser.Groups)
                    {
                        if (grp.ID == 4)
                        {
                            writer.Write("User Logged in is an Administrator");
                            break;
                        }

                        if (grp.ID == 6)
                        {
                            writer.Write("User Logged in is an Contributor");
                        }
                    }

                });
            }
            catch (Exception ex)
            {
                writer.Write(ex.ToString());
            }