Wednesday, August 24, 2016

SharePoint 2013: Get all subsites, user groups and users from the site collection using the cross-domain library and JSOM

Summary: Learn how to use the cross-domain library in apps for SharePoint to get groups and users in a grid from an app web.

Source Code: Get Groups and Users


Last modified: 8/24/2016


This sample SharePoint hosted app demonstrates how to use the cross-domain library in SharePoint 2013 to get user groups and users list in the app web. The app deploys an grid to the app web, and displays the subsites, groups and users by using the JavaScript object model (JSOM).

Description of the sample

The code that uses the cross-domain library and a third party grid control provided by jQWidgets. The control used in this sample is a trial version. The grid displays all the subsite, user groups of each subsite and users of each group. Grid features like grouping, sorting and filtering are enabled in this app. Grouping feature of this grid helps to get the list of all users, get all groups a user is member of, and all users and groups from site collection.


Figure 1. Browser window display the grid grouped by Web and Group.


Get all user groups and users from site collection

Prerequisites

This sample requires the following:
  • Visual Studio 2015
  • Office Developer Tools for Visual Studio 2015
  • A SharePoint 2013 development environment


For more information, see Get started developing apps for SharePoint.

Key components of the sample

The sample contains the following:
  • GetUserGroups project, which contains the AppManifest.xml file
  • GetUserGroups project
    • Default.aspx file, which contains references to SharePoint JavaScript resource files
    • App.js file, which contains code to fetch data and display results
    • jQWidget folder, which contains all the required JavaScript files and images for grid control.

Configure the sample

Follow these steps to configure the sample.
  • Update the SiteUrl property of the solution with the URL of the home page of your SharePoint website.

Run and test the sample

  1. Press F5 to build and deploy the app.
  2. Choose Trust It on the consent page to grant permissions to the app.
You should see an HTML page that displays five announcements.

Troubleshooting

For troubleshooting steps, visit the Troubleshooting the solution table in the cross-domain library documentation article.

Download source code: Get Groups and Users

No comments:

Post a Comment