webPart开发--获取特定用户组中所有的用户

 /// <summary>
        /// 返回特定用户组用户
        /// </summary>
        /// <returns></returns>
        private DataTable dtGroupUser()
        {

            DataTable dt = new DataTable();
            dt.Columns.Add("UserName"); //用户名
            dt.Columns.Add("LoginName");//登录名
            SPSite site = new SPSite(siteurl);
            SPWeb web = site.OpenWeb();
            foreach (SPUser user in web.SiteUsers)  //获取站点中的所有用户,对每个用户进行筛选,看是否属于所要查找的GroupName 中
            {
                for (int i = 0; i < user.Groups.Count; i++)
                {

                    if (user.Groups[i].ToString() == GroupName && user.Name.ToString() != "System Account") 
                    {
                        DataRow newRow = dt.NewRow();
                        newRow["TeamLeaderName"] = user.Name.ToString();
                        newRow["LoginName"] = user.LoginName;
                        dt.Rows.Add(newRow);
                    }
                }

            }
            return dt;
        }

转自:http://blog.csdn.net/dtlcq/article/details/4749100

posted @ 2013-02-22 11:02  天空行马  阅读(241)  评论(0编辑  收藏  举报