UserCollection 类
表示User对象的集合。
继承层次结构
System.Object
Microsoft.SharePoint.Client.ClientObject
Microsoft.SharePoint.Client.ClientObjectCollection
Microsoft.SharePoint.Client.ClientObjectCollection<User>
Microsoft.SharePoint.Client.UserCollection
命名空间: 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 UserCollection _
Inherits ClientObjectCollection(Of User)
用法
Dim instance As UserCollection
public class UserCollection : ClientObjectCollection<User>
示例
此代码示例将当前用户添加到当前网站上的访问者组。
using System;
using Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointFoundation.Samples
{
class UserCollectionExample
{
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);
}
}
}
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。