Adds a group to the collection of groups in a site collection.
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Sub Add ( _
name As String, _
owner As SPMember, _
defaultUser As SPUser, _
description As String _
)
用法
Dim instance As SPGroupCollection
Dim name As String
Dim owner As SPMember
Dim defaultUser As SPUser
Dim description As String
instance.Add(name, owner, defaultUser, _
description)
public void Add(
string name,
SPMember owner,
SPUser defaultUser,
string description
)
参数
name
类型:System.StringA string that represents the new group name.
owner
类型:Microsoft.SharePoint.SPMemberAn SPMember object that specifies the owner.
defaultUser
类型:Microsoft.SharePoint.SPUserAn SPUser object that specifies the default user for the group.
description
类型:System.StringA string that contains a description for the group.
异常
| 异常 | 条件 |
|---|---|
| ArgumentException | owner is null . |
| SPException | The group collection is read-only. -or- The owner is a role or domain group. -or- The group is not a site-level group. |
示例
The following code example creates a group in the current site collection.
Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
Try
Dim groups As SPGroupCollection = webSite.SiteGroups
Dim user As SPUser = webSite.Users("User_Name")
Dim member As SPMember = webSite.Users("User_Name")
groups.Add("Group_Name", member, user, "Description")
Finally
webSite.Dispose()
End Try
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
{
SPGroupCollection collGroups = oWebsiteRoot.SiteGroups;
SPUser oUser = oWebsiteRoot.Users["User_Name"];
SPMember oMember = oWebsiteRoot.Users["User_Name"];
collGroups.Add("Group_Name", oMember, oUser, "Description");
}
备注
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.