SPGroup class
表示在SharePoint Foundation的網站群組。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPMember
Microsoft.SharePoint.SPPrincipal
Microsoft.SharePoint.SPGroup
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public NotInheritable Class SPGroup _
Inherits SPPrincipal
'用途
Dim instance As SPGroup
public sealed class SPGroup : SPPrincipal
備註
您可以使用SPUser或SPWeb類別的Groups屬性,傳回使用者或網站群組的集合。否則,請使用SPUser類別,以傳回由使用者所擁有的群組的集合中的 [ OwnedGroups ] 屬性或SPWeb類別的SiteGroups屬性在網站集合中傳回所有群組。
使用索引子來從集合傳回單一群組。例如,如果集合指派給一個名為collGroups變數中,使用myGroups[index]在 Microsoft C# 或myGroups(index)在 Microsoft Visual Basic,其中index是集合中群組的索引編號,或者是群組的名稱。
每個群組可以由SPMember物件,並具有唯一的成員識別項 (請參閱ID屬性)。下列範例會將群組指派給SPMember物件:
SPMember oMember = oWebsite.SiteGroups["Cross-Site_Group_Name"];
如需有關群組和安全性的一般資訊,請參閱Users, Groups, and Authorization。
Examples
下列程式碼範例會變更名稱、 擁有人和網站集合中群組的描述。
Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
Try
Dim myGroup As SPGroup = webSite.SiteGroups("Original_Name")
myGroup.Name = "New_Name"
myGroup.Owner = webSite.Users("Domain_Name\User")
myGroup.Description = "Description"
myGroup.Update()
Finally
webSite.Dispose()
End Try
using (SPWeb oWebsite = SPContext.Current.Site.RootWeb)
{
SPGroup oGroup = oWebsite.SiteGroups["Original_Name"];
oGroup.Name = "New_Name";
oGroup.Owner = oWebsite.Users["Domain_Name\\User"];
oGroup.Description = "Description";
oGroup.Update();
}
注意事項 |
---|
某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects。 |
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.