GroupCollection 類別
代表Group物件的集合。
繼承階層架構
System.Object
Microsoft.SharePoint.Client.ClientObject
Microsoft.SharePoint.Client.ClientObjectCollection
Microsoft.SharePoint.Client.ClientObjectCollection<Group>
Microsoft.SharePoint.Client.GroupCollection
命名空間: Microsoft.SharePoint.Client
組件: Microsoft.SharePoint.Client.Silverlight (在 Microsoft.SharePoint.Client.Silverlight.dll 中); Microsoft.SharePoint.Client.Phone (在 Microsoft.SharePoint.Client.Phone.dll 中) Microsoft.SharePoint.Client (在 Microsoft.SharePoint.Client.dll 中)
語法
'宣告
Public Class GroupCollection _
Inherits ClientObjectCollection(Of Group)
'用途
Dim instance As GroupCollection
public class GroupCollection : ClientObjectCollection<Group>
範例
本程式碼範例會加入目前的網站上的 [訪客] 群組中的目前的使用者。
using System;
using Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointFoundation.Samples
{
class GroupCollectionExample
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
Web site = clientContext.Web;
GroupCollection collGroup = site.SiteGroups;
// Get the visitors group, assuming its ID is 4.
Group visitorsGroup = collGroup.GetById(4);
User currentUser = site.CurrentUser;
UserCollection collUser = visitorsGroup.Users;
collUser.AddUser(currentUser);
clientContext.Load(currentUser);
clientContext.Load(visitorsGroup);
clientContext.ExecuteQuery();
Console.WriteLine(currentUser.Title + " added to group " + visitorsGroup.Title);
}
}
}
執行緒安全
這類型的任何公用 static (共用 於 Visual Basic 中) 成員是安全執行緒。不保證任何執行個體成員都是安全執行緒。