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.

Wednesday, February 15, 2012

getting users from SharePoint Groups and Binding them to Simple HTML Table


try
            {
                string strAllUsers = string.Empty;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    strAllUsers += "<Table width='100%' cellpadding='0' cellspacing='0'>";
                    strAllUsers += "<Tr>";
                    strAllUsers += "<Td colspan='3' bgcolor='#add8e6'>";
                    strAllUsers += "</Td>";
                    strAllUsers += "</Tr>";
                    strAllUsers += "<Tr>";
                    strAllUsers += "<Td colspan='3' Align='Center'>";
                    strAllUsers += "<Strong>";
                    strAllUsers += "Users Using this Site";
                    strAllUsers += "</Strong>";
                    strAllUsers += "</Td>";
                    strAllUsers += "</Tr>";
                    strAllUsers += "<Tr>";
                    strAllUsers += "<Td bgcolor='#add8e6'>";
                    strAllUsers += "<Strong>";
                    strAllUsers += "UserName";
                    strAllUsers += "</Strong>";
                    strAllUsers += "</Td>";
                    strAllUsers += "<Td bgcolor='#add8e6'>";
                    strAllUsers += "<Strong>";
                    strAllUsers += "SharePoint Group";
                    strAllUsers += "</Strong>";
                    strAllUsers += "</Td>";
                    strAllUsers += "<Td bgcolor='#add8e6'>";
                    strAllUsers += "<Strong>";
                    strAllUsers += "EmailID";
                    strAllUsers += "</Strong>";
                    strAllUsers += "</Td>";
                    strAllUsers += "</Tr>";
                    strAllUsers += "<Tr>";
                    strAllUsers += "<Td colspan='3' bgcolor='#add8e6'>";
                    strAllUsers += "</Td>";
                    strAllUsers += "</Tr>";
                    SPWeb currentWeb = SPContext.Current.Web;
                    foreach (SPGroup grp in currentWeb.Groups)
                    {
                        foreach (SPUser user in grp.Users)
                        {
                            string strUser = string.Empty;
                            string strGroup = string.Empty;
                            string strUserEmail = string.Empty;
                            strUser = user.Name;
                            strGroup = grp.Name;
                            strUserEmail = user.Email;
                            strAllUsers += "<Tr>";
                            strAllUsers += "<Td>";
                            strAllUsers += strUser;
                            strAllUsers += "</Td>";
                            strAllUsers += "<Td>";
                            strAllUsers += strGroup;
                            strAllUsers += "</Td>";
                            strAllUsers += "<Td>";
                            strAllUsers += strUserEmail;
                            strAllUsers += "</Td>";
                            strAllUsers += "</Tr>";
                            strAllUsers += "<Tr>";
                            strAllUsers += "<Td colspan='3' bgcolor='#add8e6'>";
                            strAllUsers += "</Td>";
                            strAllUsers += "</Tr>";
                        }
                    }
                    strAllUsers += "</Table>";
                    writer.Write(strAllUsers);
                });
            }
            catch (Exception ex)
            {
                writer.Write(ex.ToString());
            }

No comments:

Post a Comment