首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取具有给定站点url的sharepoint组的任何方式

获取具有给定站点url的sharepoint组的任何方式
EN

Stack Overflow用户
提问于 2010-05-18 10:48:24
回答 1查看 2.5K关注 0票数 0

我被卡住了。假设我创建了5个站点。对于每个组,我都会创建几个sharepoint组。因此,我创建一个下拉列表控件来绑定5个站点,当我单击那里的任何网站时,我将在其上创建sharepoint组。但是我总是看到用于绑定这些组的下拉列表仍然没有改变。我的意思是,每次它只绑定一些sahrepoint中的默认组。新创建的组不是。

我有这样的困惑

web.AssociatedGroups web.Groups web.SiteGroups

我们用的是哪一种?请引导我

这里是我的代码片段

私有空BindSPGroupsToDropDownList(DropDownList ddl,string siteUrl) {

代码语言:javascript
复制
        ddl.Items.Clear();
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
           {
               using (SPSite site = new SPSite(siteUrl))
               {
                   using (SPWeb web = site.OpenWeb())
                   {
                       //web.SiteGroups
                       foreach (SPGroup spGroup in web.Groups)
                       {


                           ddl.Items.Add(new ListItem(spGroup.Name.Trim(), spGroup.ID.ToString()));



                       }

                   }
               }
           });
        }

}

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2010-05-18 11:12:44

您没有显示如何添加组,因此很难理解为什么不能列出它们。

一些考虑因素:

  1. 组的作用域是在站点集合级别,即在web (SPWeb)级别上不存在组的概念;只有在SPSite级别
  2. ,我几年前为管理组编写了代码,因此我不记得不同属性之间的区别。查看我的代码,我使用SPWeb.SiteGroups测试一个组是否存在,并添加一个新组。

这是我的--稍微匿名--代码:

代码语言:javascript
复制
public static void CreateSiteGroup(SPSite site, string strGroupName, string strGroupDesc, string strGroupOwner) {
    if (site == null) {
        string message = GetMessagePrefix() + " Site is null";
        XxxLog.Error(XxLogEventId.Common, message, XxxLogCategory.CommonBusiness);
     } else if (String.IsNullOrEmpty(strGroupName)) {
        string message = GetMessagePrefix() + " The group name is empty";
        XxxLog.Error(XxxLogEventId.Common, message, XxxLogCategory.CommonBusiness);
     } else {
        try {
            using (SPWeb rootWeb = site.RootWeb) {
                SPMember owner;
                if (String.IsNullOrEmpty(strGroupOwner)) {
                    owner = rootWeb.CurrentUser;
                } else {
                    if (!ContainsGroup(site, strGroupOwner)) {
                        string message = GetMessagePrefix() + " Can not find owner group name: " + strGroupOwner;
                        XxxLog.Error(XxxLogEventId.Common, message, XxxLogCategory.CommonBusiness);
                        return;
                    } else {
                        owner = rootWeb.SiteGroups[strGroupOwner];
                    }
                }

                if (!ContainsGroup(site, strGroupName)) {
                    rootWeb.SiteGroups.Add(strGroupName,
                                           owner,
                                           null, // no default user
                                           strGroupDesc);
                } else {
                    string message = GetMessagePrefix() + " The group " + strGroupName + " was already present";
                    XxxLog.Info(message, XxxLogCategory.CommonBusiness);
                }
            }
        } catch (Exception e) {
           string message = GetMessagePrefix() + " Cannot create " + strGroupName + " group";
           XxxLog.Error(XxxLogEventId.Common, message,e, XxxLogCategory.CommonBusiness);
        }
     }
  }

  public static Boolean ContainsGroup(SPSite site, string name) {
     SPGroup group = null;
     using (SPWeb rootWeb = site.RootWeb) {
        foreach (SPGroup g in rootWeb.SiteGroups) {
           if (g.Name.ToUpper().Equals(name.ToUpper())) {
              group = g;
              break;
           }
        }
     }

     return (group != null);
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2856457

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档