Create list from custom template in SharePoint with PowerShell

This examples shows how to create new lists from custom list templates in SharePoint using PowerShell and CSOM. Custom list templates are STP-files uploaded to the List Template Gallery on the site. This should work both on-premises (2013/2016) and Online (Office 365).

Note: This example uses commands from the Office Dev PnP PowerShell library, ex. “Connect-PnPContext”. I recommend using this library for working this PowerShell and SharePoint (both Online and On-Premises).

Enable ratings in SharePoint with PowerShell and CSOM

In document libraries it is possible to enable ratings, both likes and average score (1-5). In this article I will cover how to enable “Likes” on the Pages library in a publishing site.

When configuring libraries manually, this is enabled from the “Rating settings” in the library:

enableratings

But when we follow the remote provisioning pattern to create new sites by using PowerShell and CSOM, there is currently no available function in the API for this. This pattern is the recommenced approach when working with SharePoint Online or SharePoint 2013/2016 without access to server side PowerShell or code.

To understand what is required to programmatic enable ratings I had to, as always with SharePoint, inspect the code behind with a reflection tool like DotPeek.

How to enable likes ratings

This show the procedure to enable ratings with Likes on a Pages library. To enable “Star rating” (1-5 average) this would be similar, but not covered in this post.

  1. Add the required fields to the library
    FieldName Guid
    AverageRating 5a14d1ab-1513-48c7-97b3-657a5ba6c742
    RatingCount b1996002-9167-45e5-a4df-b2c41c6723c7
    RatedBy 4D64B067-08C3-43DC-A87B-8B8E01673313
    Ratings 434F51FB-FFD2-4A0E-A03B-CA3131AC67BA
    LikesCount 6E4D832B-F610-41a8-B3E0-239608EFDA41
    LikedBy 2CDCD5EB-846D-4f4d-9AAF-73E8E73C7312
  2. Add “LikesCount” to default view
  3.  Add “Ratings_VotingExperience” to RootFolder’s property bag

Use PowerShell to enable ratings

Note: This function requires the Office Dev PnP PowerShell library to be installed and loaded in the current PowerShell session. I recommend using this library for working with PowerShell and SharePoint (both Online and On-Premises).

Example: How to use this function with a site

Using this with subsites within the Site Collection would require some extension to the function, as the Fields always are loaded form the RootWeb, but the library reside in the subsite.

When we have run the “Enable-CustomLikesRatingsOnLibrary” function on the desired library, we can see that Likes now are available:

ratings-library

Summary

Using this function it is now possible to provision new sites with PowerShell and CSOM and enable likes rating on libraries.

Enabling scheduling on Publishing Pages in SharePoint Online (Office 365) using CSOM and PowerShell

Scheduling is easily enabled through the web interface when configuring the “Pages” library, but when deploying solutions using PowerShell, this must be automated as part of the configuration. Unfortunately, as many other sources also state, this is not directly supported in the Client Side API (CSOM).

The solution is to manually set up the Pages library the same way Microsoft does by adding two event receivers, changing some columns from hidden to visible and adding them to the default view.

Note: This example uses commands from the Office Dev PnP PowerShell library, ex. “Get-SPOContext”. I recommend using this library for working this PowerShell and SharePoint (both Online and On-Premises).

Function to enable Scheduling on a library on a given web site:

On line 11 an additional function is needed to create the parameters for the “Load” method:

How to enable scheduling:

Unable to search for pages in SharePoint Online when using Managed Navigation

This is a summary of an issue we have had with publishing pages not being indexed, and then unable to build the search-driven pages we wanted using for example Content Search Web Part. This occured in SharePoint Online (Office 365) and we have only had this issue with a couple of tenants. So my guess is that most tenants are working fine, but if you should come across this strange behavior, I hope this post can help you save some time.

The issue

  • Created a Publishing Site
  • Added a Content Type and a Page Layout, created a few test articles
  • Added a Content Search Web Part and set up a query to return articles for the Content Type created above
  • Waited a long time (normal)
  • No results (oops)
  • Tried to reindex the library (curious)
  • No results (worried)
  • Retried all the steps (scared)
  • No results (desperate)
  • Got coffee (calm)
  • No results (called support)

I guess you get it. Something was very wrong and I was stuck on not getting any results back. On-Premises this would probable been one of those situations a full crawl, or at worst a index reset, had fixed it. But running in Office 365 we don’t have these abilities.

The workaround

After some trial and error I understood what was causing the issue, and got this workaround:

  • Go to “Site Settings”
  • Select “Navigation” under “Look and feel”
  • Uncheck these options:
    • Add new pages to navigation automatically
    • Create friendly URLs for new pages automatically

search-mn-error-1

All pages created and published after making this change was indexed and showed up as expected. Unfortunately all the pages created before doing this change was a lost cause. Believe me, I tried a lot but unable to get them indexed.

The fix

As being on Office 365 this issue was addressed with Microsoft Support, and after a while they released a fix.

Unfortunately I suspect this error can still occur in some scenarios, and to make sure we don’t run into this trouble again, a recommendation is to avoid using the Managed Navigation set up as shown above just to be safe.

Setting up a development environment for Office 365 and SharePoint Online

As we more and more evolve from working exclusively with SharePoint on-premises with our complex local SharePoint farm rigged with several virtual machines eating up our highly spec’d laptop, the new way of working with SharePoint in-cloud offers a more attractive setup for us developers.

My background before starting with SharePoint, as for most others, was as a general programmer used to pretty simple and lightweight development environments. I must say I almost had forgotten what a lightweight and clean development environment feels like. It feel like coming home after a long and tough journey 😉

Setting up a development environment for doing Office 365 and SharePoint Online development is really easy, I that’s the reason I chose to create this post it just to keep a note to myself what the essentials are.

o365-dev-env-1

Where to run it

I recommend to set up a dedicated virtual machine for this setup. I prefer using Hyper-V as it is included in Windows 8, and for many other reasons.

Specification:

  • 4 cores (minimum 2)
  • 8 GB RAM or more (dynamic)
  • 80 GB disk (expanding)

Getting the necessary software

Operative system

  • Windows 8.1 x64 with Update

Software

  • Visual Studio 2013 Update 3 x86
  • Office 2013 SP1 x86
  • SharePoint Designer 2013 x86
  • Google Chrome (set as default)

SDKs

These SDKs are pre-requirements to getting started with development against Office 365. It is important to install them in the listed order to avoid errors.

Title

Description

URL

Office Developer Tools for Visual Studio 2013 – July 2014 update

This can also be installed from Web Platfrom installer.

http://msdn.microsoft.com/en-us/office/aa905340.aspx

Microsoft Online Services Sign-In Assistant for IT Professionals BETA

The Microsoft Online Services Sign-In Assistant provides end user sign-in capabilities to Microsoft Online Services, such as Office 365.

http://www.microsoft.com/en-my/download/details.aspx?id=39267

Azure Active Directory Module for Windows PowerShell

Use Windows PowerShell cmdlets to manage your Windows Azure tenant.

http://msdn.microsoft.com/en-us/library/azure/jj151815.aspx#bkmk_installmodule

SharePoint Online Management Shell

The SharePoint Online Management Shell is a tool that contains a Windows PowerShell Module to manage your SharePoint Online subscription in the Office 365. http://www.microsoft.com/en-us/download/details.aspx?id=35588
Azure SDK for .NET (OPTIONAL) Install this if you plan to develop provider hosted ASP.NET apps in Azure. http://azure.microsoft.com/en-us/downloads/ (VS 2013 install)

Development tools

 Going from on-premises development to cloud, first of all reduces the available tools. Luckily a few of those contributing with their excellent tools have also made them compatible with SharePoint Online. These tools I recommend to increase your productivity working with developing solutions for SharePoint Online. Spend some time to learn what you can gain from using them.

Title

Description

URL

CAML Designer 2013

http://www.camldesigner.com/

Fiddler

http://www.telerik.com/fiddler

SharePoint Client Browser

https://spcb.codeplex.com/

SharePoint Search Query Tool

https://sp2013searchtool.codeplex.com/

Utilities

There as some basic utilities I always find handy to have available on every computer I work on. So this is only a recommendation, and not necessary to get the environment working.

Setting it up

This is pretty a straight forward top-down installation. Only be careful to click away some of the ad-ware stuff on the utilities to avoid getting crazy toolbars in your not-default browser IE.

One important factor is to install the SDKs in the right order as listed. I had some trouble getting this to work, and it turned out installing SharePoint Online Management shell too early gave some bad consequences.

Troubleshooting

When I tried to install Azure Active Directory Module for Windows PowerShell it got an error:

“In order to install Windows Azure Active Directory Module for PowerShell, you must have Microsoft Online Services Sign-In Assistant version 7.0 or greater installed on this computer.”.

For the time being I had version 7.250.4303.0 installed, I this error message made no sense. It turns out there is a newer BETA version (7.250.4551.0) that is required. I have linked to the correct version above, so just make sure you are using it.

Summary

Getting started with developing for SharePoint Online in Office 365 is a much more pleasant journey than the traditional on-premises story. We are now able to be productive using a very lightweight machine with a small set of tool available to do our work.

I wrote this guide primarily for my own use I as tend to forget all those small details between each time I set up a new environment, but I also hope it can help others getting started as quick and hassle-free as possible with developing for SharePoint Online.

NOTE: This topic is always subject to change as new versions roll out all the time.

Adding comments, likes and follow from Yammer into you own SharePoint solutions

With the Yammer Embed API adding comments, likes and follow content is quite easy to achieve. Using this embed API has a great benefit as it is developed and maintained by Yammer, and will require very little effort to integrate. Features beyond the actions (like and follow) and the feed (comments) can be accomplished with either the REST or JavaScript API, but this will require more effort (reference: https://developer.yammer.com/yammer-sdks/). Integrating Yammer requires an external JavaScript file to be referenced, one or more placeholders (HTML div-tags) and local JavaScript function call to the API to initialize the integration.

Example of a news article based on a Page Layout in SharePoint Online with like, follow and comments from Yammer:

yammer-sp2013-onpremises-1

Embed API reference

</p>
<script type="text/javascript" src="https://assets.yammer.com/assets/platform_embed.js"></script></p>

Comments Feed

Comments can be made for many types of activities, in this example “page”. Yammer can maintain the relationship between the article and the feed either automatic by the URL in the browser, or it can be set explicit to ensure that the ID is unique. The first event on this article will trigger Yammer to create a activity page. This page can be enhanced with further metadata like a description and an image.

Example how this is displayed in SharePoint:

yammer-sp2013-onpremises-2

  Example how this is displayed in the  Yammer feed: yammer-sp2013-onpremises-3

Example on a activity page in Yammer:

yammer-sp2013-onpremises-4

Example code


<div id="yammer-page-feed" style="height:400px;width:500px;"></div>

<script>

yam.connect.embedFeed({

container: '#yammer-page-feed'

, network: 'o365.areflyen.no'

, feedType: 'open-graph'

, feedId: ''

, config: {

use_sso: true

, header: false

, footer: false

, showOpenGraphPreview: false

, defaultToCanonical: false

, hideNetworkName: false

, promptText: 'Comment on this article'




}

, objectProperties: {

url: ''

, type: 'page'

}

});

</script>

Like button

The practical effect of the “Like” action is limited. The button only shows the state for the current user (Like/Liked) and generates an activity. No total count of likes is available. When a user likes a page, it will also automatically be followed.

yammer-sp2013-onpremises-5

Example code


<div id="yammer-like"></div>

<script>

yam.connect.actionButton({

container: "#yammer-like",

network: "o365.areflyen.no",

action: "like"

});

</script>

Follow button

When following a page, you will subscribe to the activities on the current page. If you make a comment you will automatically follow the page.

yammer-sp2013-onpremises-6

Example code


<div id="yammer-like"></div>

<script>

yam.connect.actionButton({

container: "#yammer-follow",

network: "o365.areflyen.no",

action: "follow"

});

</script>

Summary

Yammer gives us easy to use API to make the switch from SharePoint Social to Yammer possible. Even if these examples are demonstrated in SharePoint Online, the same solution can be applied to On-Premises. Gaining the best user experience On-Premises will be by implementing a Single Sign-On (SSO) solution between you local network and Yammer. Disclaimer: Both SharePoint and Yammer is in continuous development, and the API and user interface shown in the screenshots have changed from the time this post was written.

Commonly used Web Templates in SharePoint 2013 with screenshots

I created a list of all the common used web templates in SharePoint 2013 with a screenshot showing how the site looks out-of-the-box primary to have for my own reference, but thought it might be interesting for other to access to so I posted this as an article.

This is the web templates available when creating new site collections through Central Admin with SharePoint 2013 Enterprise SP1. As many know there are lots of more templates, but these are the ones common available, and I recommend to stick to these when building solutions.

Please feel free to copy the screenshots for your own use.

Collaboration

Name

WebTemplateId

Screenshot

Team Site

STS#0

Team Site

Blog

BLOG#0

 Blog

Developer Site

DEV#0

 Developer Site - DevHome

Project Site

PROJECTSITE#0

 Project Site

Community Site

COMMUNITY#0

 Community Site - Community Home

Enterprise

Name

WebTemplateId

Screenshot

Document Center

BDR#0

 Document Center

eDiscovery Center

EDISC#0

 eDiscovery Center

Records Center

OFFILE#1

 Records Center

Business Intelligence Center

BICenterSite#0

 Business Intelligence Center

Enterprise Search Center

SRCHCEN#0

 Search - Enterprise

My Site Host

SPSMSITEHOST#0

 MySite Host

Community Portal

COMMUNITYPORTAL#0

 Community Portal

Basic Search Center

SRCHCENTERLITE#0

 Search - Basic

Visio Process Repository

visprus#0

 Visio Process Repository

Publishing

Name

WebTemplateId

Screenshot

Publishing Portal

BLANKINTERNETCONTAINER#0

 Publishing Portal

Enterprise Wiki

ENTERWIKI#0

 Enterprise Wiki

Product Catalog

PRODUCTCATALOG#0

 Product Catalog

 

Download all screenshots

Note: If you are using Office 365 please note that at the time this article was posted the “Product Catalog” is missing and a special version of the “Team Site” template is available.