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.

Tuesday, December 06, 2011

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());
            }

No comments:

Post a Comment