Retrieve SiteCollection Groups

SharePoint 2010 now supports the client side programming using Client API Classes and namespaces. Using those class references, we can see how to retrieve the list of Site collection groups.

Before start the code, add the two namespaces Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime as references to the project.

The above mentioned two DLL’s are available under " SharePoint Root > ISAPI "

using Microsoft.SharePoint.Client;

———–

ClientContext context = new ClientContext("http://spserver");
Web web = context.Web;         
GroupCollection groups = web.SiteGroups;
context.Load(groups);
context.ExecuteQuery();
foreach (Group grp in groups)
{
        Console.WriteLine(grp.Title);
}
Console.WriteLine("Press any key to continue…");
Console.Read();

Declare the ClientContext to get the context information of a site collection and then load the site collection groups to the that. Then execute the ClientContext using context.ExecuteQuery() to retrieve the collection of groups available under particular SharePoint Site Collection.

The result we got for the above mentioned code as follows,

result1


Deprecated: Function wp_img_tag_add_loading_attr is deprecated since version 6.3.0! Use wp_img_tag_add_loading_optimization_attrs() instead. in /home/ktskumar/public_html/wp-includes/functions.php on line 6031

Deprecated: Function wp_get_loading_attr_default is deprecated since version 6.3.0! Use wp_get_loading_optimization_attributes() instead. in /home/ktskumar/public_html/wp-includes/functions.php on line 6031
Shantha Kumar
Shantha Kumar
Articles: 280