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.

Friday, April 13, 2012

How to check if the Logged user is in Multiple Groups....!

try
            {
                writer.Write("<Table width='100%'>");
                writer.Write("<Tr>");
                writer.Write("<Td Align='Center'>");
                writer.Write("<Strong>");
                writer.Write("How to check if the current logged user is in Multiple Groups...!");
                writer.Write("</Strong>");
                writer.Write("<Td>");
                writer.Write("</Tr>");
                bool strCurrentUser = false;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWeb currentWeb = SPContext.Current.Web;
                    SPGroupCollection grp = currentWeb.Groups;
                    foreach (SPGroup group in grp)
                    {
                        if (group.ID == 5)
                        {
                            strCurrentUser = true;
                        }
                    }
                    if (strCurrentUser == false)
                    {
                        writer.Write("<Tr>");
                        writer.Write("<Td>");
                        writer.Write("<Strong>");
                        writer.Write("Current user is not an Administrator...!");
                        writer.Write("</Strong>");
                        writer.Write("<Td>");
                        writer.Write("</Tr>");
                    }
                    else
                    {
                        writer.Write("<Tr>");
                        writer.Write("<Td>");
                        writer.Write("<Strong>");
                        writer.Write("Current User is an Administrator");
                        writer.Write("</Strong>");
                        writer.Write("<Td>");
                        writer.Write("</Tr>");
                    }

                });
                writer.Write("</Table>");

            }
            catch (Exception ex)
            {

                writer.Write(ex.ToString());
            }


No comments:

Post a Comment