次の方法で共有


GroupCollection class

Represents a collection of Group objects.

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.ClientObjectCollection
      Microsoft.SharePoint.Client.ClientObjectCollection<Group>
        Microsoft.SharePoint.Client.GroupCollection

Namespace:  Microsoft.SharePoint.Client
Assembly:  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)

Syntax

'Declaration
Public Class GroupCollection _
    Inherits ClientObjectCollection(Of Group)
'Usage
Dim instance As GroupCollection
public class GroupCollection : ClientObjectCollection<Group>

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 GroupCollectionExample
    {
        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

GroupCollection members

Microsoft.SharePoint.Client namespace