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

Wednesday, August 10, 2016

Difference between sp.js and sp.runtime.js

The difference between sp.js and sp.runtime.js is


  • SP.js includes the SharePoint object modal references, such as web, lists, client context (which is used for representing the context of SharePoint Objects and operations), etc. It provides the types and members similar to the server object model namespace Microsoft.SharePoint to work with top-level sites, sub-sites and their lists and libraries.

  • SP.Runtime.js includes the details between client and server communication. It contains the runtime object of JavaScript and encapsulate all classes of client object model and the server interaction.


When you use JSOM, import the following libraries in the specified order.

  1. ASP.NET Ajax library
  2. sp.runtime.js
  3. sp.js 

Thursday, July 7, 2016

SharePoint 2016 step by step installation

Following are the steps to install and configure SharePoint 2016 single Server Farm


Prerequisite/Environment

  • Windows Server 2012 R2

  • SQL Server 2012 Enterprise
  • SharePoint 2016 Prerequisites are installed.



  1. Start SharePoint 2016 RTM installation.


Start SharePoint 2016 RTM installation.


  1. Once the installation is complete, run the configuration wizard
SharePoint 2016 Run Configuration Wizard
  1. Select ‘Create a new Server’
SharePoint 2016 Configuration Wizard - connect to a server farm


  1. Provide the Database server details and click next. In this instance of single server farm, provide the current server and DB details. Since installing SharePoint 2016 in standalone machine is not supported, we need to add the current server to domain in order to configure single server farm environment. Refer to my blog post on Configuring Active Directory Domain Services for SharePoint 2016 Environment


SharePoint 2016 Configuration Wizard - Database Settings


  1. Provide Passphrase
SharePoint 2016 Configuration Wizard - Security Settings


  1. Specify server role. Select the role for the server you’re installing in the server farm. If the instance is a single server farm, then select Single Server Farm.


SharePoint 2016 Configuration Wizard - Server Role Settings


  1. Specify the central administration port number and select the authentication provide for the web application. In this instance we are selecting NTLM authentication.
SharePoint 2016 Configuration Wizard - Central Administration Settings


  1. Select Next to complete the configuration.
SharePoint 2016 Configuration Wizard


SharePoint 2016 Configuration Wizard

SharePoint 2016 Central Administration Site

Configuration Active Directory Domain Services for SharePoint 2016 Single Server Environment

Environment: Windows Server 2012 R2, SharePoint 2016 RTM Prerequisite: Install ADLDS (https://technet.microsoft.com/en-in/library/jj574166.aspx)

Following are the steps to configure AD DS for a SharePoint 2016 Single Server Farm installation.
Start Server Manager > Select AD DS and click on more… to complete the required configuration for AD DS in the server


Configure AD DS
Click on the post deployment configuration action
Configure AD DS


Select “Add a new forest”, provide the domain name and click Next button
AD DS domain name
Provide the Directory Services Restore Mode password and click Next
Domain Controller Options
Ignore the warning message and click next


DNS Options


AD DS Domain Name
Specify the AD DS database and log location path.
AD DS Paths


Verify the details provide and click next
AD DS Review Settings


When the following error message (“Verification of prerequisites for Domain Controller promotion failed”) occurs during perquisites check, then reset the password for Administrator Account and run the prerequisite again


AD DS Prerequisites Check

AD DS Prerequisites Check
Click Install after successful prerequisite checks.


AD DS Prerequisites Check
AD DS Installation
Restart the server after successful installation.
AD DS Installation - Restart Server
Login with the credentials for new domain.
AD DS Installation - Verify Authentication


Add Users to new AD

Select Active Directory Users and Computers from Server Manager > Tools menu
AD DS - Add New Users
Add new user details
AD DS - Add New Users
Verify authentication after creating users. Now you can use this domain to configure SharePoint 2016 in a single server environment.

Thursday, June 23, 2016

SharePoint 2016 Products Configuration Wizard failed throwing ‘One or more types failed to load’

Environment: SharePoint 2016 Enterprise RTM, Windows Server 2012 R2
Scenario: Install SharePoint 2016 Enterprise RTM and configure
Issue: The SharePoint Products Configuration Wizard failed throwing ‘One or more types failed to load’
SharePoint Products Configuration Wizard failed
Troubleshooting:
  1. Looked into the configuration log file and noticed the following error message
Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral’
Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral’
  1. Download and Install the WCF Data Services Client for OData package and NuGet package Manager


  1. Use NuGet package manager to install the OData package


  1. Upgrade if you already have NuGet in your machine using following command


Nuget.exe update –self (This automatically get the update from web using your internet)
update NuGet
  1. The package can be installed from Visual Studio by navigating to Tools > NuGet Package Manager > Package Manager Console
NuGet Package Manager


  1. Make sure that you open a sample web project and execute the following command to install the package.
Install-package Microsoft.Data.OData
Install Package

  1. Run the configuration wizard again successfully

Tuesday, June 21, 2016

SharePoint 2016 Configuration Wizard failed with error ‘CacheHostInfo is null’.

Environment: SharePoint 2016 Enterprise RTM, Windows Server 2012 R2
Scenario: Install SharePoint RTM and run configuration wizard
Issue: The installation completed successfully however the SharePoint Products Configuration Wizard failed by throwing cacheHostInfo is null' error.
Configuration Wizard failed
Troubleshooting:
  1. Tried to repair distributed cache on the server by executing the following line of PowerShell script
Get-SPServiceInstance
$s = Get-SPServiceInstance <<Distributed Cache GUID>>
$s.delete()
Add-SPDistributedCacheServiceInstance
For some reasons, the script throws following error on line Add-SPDistributedCacheServiceInstance
Add-SPDistributedCacheServiceInstance : Could not load file or assembly 'Microsoft. ApplicationServer.Caching.Configuration, Version=1.0.0.0, culture=neutral, PublicKeyToken=31bf3856ad364e35'or one of its dependencies. The system cannot find the file specified.
Add Distributed Cache Service Instance
  1. Started AppFabric Caching Service and added the SPDistributedCacheServiceInstance successfully.

Add Distributed Cache Service Instance

  1. As running the configuration wizard again failed, downloaded and Installed Cumulative Update 7 (KB3092423) for Microsoft AppFabric 1.1 for Windows Server

  1. Restart the computer after applying this cumulative update package.

  1. After successfully installing the CU package. Execute the following PowerShell script to remove the caching service instance.
$SPFarm = Get-SPFarm
$cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString()
$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local
$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);
$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}
$serviceInstance.Delete()

Remove the caching service instance.

  1. Run the Configuration Wizard again and the configuration is successful.

Configuration successful

References: