UserCollection.AddUser メソッド
Adds the user specified by the user parameter to the collection.
名前空間: 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 Function AddUser ( _
user As User _
) As User
'使用
Dim instance As UserCollection
Dim user As User
Dim returnValue As User
returnValue = instance.AddUser(user)
public User AddUser(
User user
)
パラメーター
user
型: Microsoft.SharePoint.Client.UserA user to add.
戻り値
型: Microsoft.SharePoint.Client.User
Returns a User instance representing the user to add.
例外
例外 | 条件 |
---|---|
[Microsoft.SharePoint.SPException] | The user does not exist or is not unique. Error code: -2130575276. The collection is read-only. Error code:-1. |
[System.Security.SecurityException] | The collection is the farm administrators group and the specified user is not a computer administrator. Error code: -1. |
[System.UnauthorizedAccessException] | 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;
collUser.AddUser(currentUser);
clientContext.Load(currentUser);
clientContext.Load(visitorsGroup);
clientContext.ExecuteQuery();
Console.WriteLine(currentUser.Title + " added to group " + visitorsGroup.Title);
}
}
}