Compartir a través de


User Class

Represents a user in Microsoft SharePoint Foundation.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.Principal
      Microsoft.SharePoint.Client.User

Namespace:  Microsoft.SharePoint.Client
Assemblies:   Microsoft.SharePoint.Client.Silverlight (in Microsoft.SharePoint.Client.Silverlight.dll);  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)

Syntax

'Declaration
<ScriptTypeAttribute("SP.User", ServerTypeId := "{ae70d2a4-ec46-4ed9-9b1e-9d0245754463}")> _
Public Class User _
    Inherits Principal
'Usage
Dim instance As User
[ScriptTypeAttribute("SP.User", ServerTypeId = "{ae70d2a4-ec46-4ed9-9b1e-9d0245754463}")]
public class User : Principal

Examples

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);
        }
    }
}

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.

See Also

Reference

User Members

Microsoft.SharePoint.Client Namespace