Skip to main content
 首页 » 编程设计

c#之Sharepoint:SPweb.Groups.GetByName(groupName) 抛出异常

2024年02月01日27Renyi-Fan

我正在尝试以编程方式(使用 .Net)创建一个新的 SharePoint 组,为此我使用以下 C# 代码

                //greate group with no users: 
 
                web.SiteGroups.Add(groupName, groupOwner, null, description); 
                //Parameters are defined earlier in the code such as: 
                //   string groupName 
                //   SPUser groupOwner 
                //   string description 
 
                web.Update(); 
                SPGroup newGroup = web.Groups.GetByName(groupName); 

创建工作正常,但当我尝试访问该组时抛出异常,提示“找不到组”。 找不到该组的原因是什么?我该如何解决(我需要访问该组以获取更多代码)?如果我在人员和群组下查看 SharePoint,群组就在那里。

感谢任何帮助,谢谢。

请您参考如下方法:

试试这个:SPGroup oGroup = web.SiteGroups[groupName];