User 类
Represents a user in Microsoft SharePoint Foundation.
继承层次结构
System.Object
Microsoft.SharePoint.Client.ClientObject
Microsoft.SharePoint.Client.Principal
Microsoft.SharePoint.Client.User
命名空间: 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 NotInheritable Class User _
Inherits Principal
用法
Dim instance As User
public sealed class User : Principal
备注
Use the AllUsers property of the Web class to return all the users of a site. This includes users granted permissions directly, users granted permissions through a group who have then visited the site, and users who have been referenced in a person field, such as being assigned a task. Calling AllUsers[name] will throw an exception if the user is not there.
Use the SiteUsers property of the Web class to return all the users in the site collection.
Use the GetAllAuthenticatedUsers method of the Utility class to return all authenticated users of a site.
Use the GetUniqueUsers method of the SPAlertCollection class to return a list of users for a collection of alerts.
Otherwise, use the Users property of the Group or Web class to return the users in a group or site.
Use an indexer to return a single user from the collection. For example, if the collection is assigned to a variable named collUsers, use collUsers[index] in C#, or collUsers(index) in Visual Basic, where index is either the index number of the user in the collection or the user name of the user.
Every user has a unique member ID (ID property), has the permissions associated with that membership, and can be represented by an SPMember object. The following example assigns a user to an SPMember object, given a specified SharePoint Web site:
Dim oWebsite As SPWeb = SPContext.Current.Web
Dim oMember As SPMember = oWebsite.AllUsers("Domain\\User_Alias")
SPWeb oWebsite = SPContext.Current.Web;
SPMember oMember = oWebsite.AllUsers["Domain\\User_Alias"];
For general information about users and security, see Security, Users, and Groups in Windows SharePoint Services.
示例
This code example adds the current user to the visitors group on the current site.
using System;
using Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointFoundation.Samples
{
class UserExample
{
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 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。