Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

UserCollection.AddUser Method

Adds the user specified by the user parameter to the collection.

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

public User AddUser(
	User user


Type: Microsoft.SharePoint.Client.User

A user to add.

Return Value

Type: Microsoft.SharePoint.Client.User
Returns a User instance representing the user to add.


The user does not exist or is not unique. Error code: -2130575276. The collection is read-only. Error code:-1.


The collection is the farm administrators group and the specified user is not a computer administrator. Error code: -1.


The current user has insufficient permissions. Error code: -2147024891.

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 UserCollection_AddUserExample
        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;


            Console.WriteLine(currentUser.Title + " added to group " + visitorsGroup.Title);

© 2015 Microsoft