Idempotent Site Scripts for SharePoint

Image by geralt on Pixabay

As you probably are aware, SharePoint site scripts are used to set up content and settings in SharePoint sites. They’re applied using site designs, which allow the same script to be reused with different names and permissions. Site designs can be applied when a site is created, when it’s added to a hub site, or on demand via PowerShell or the SharePoint UI.

Continue reading

Using SharePoint Permissions in Microsoft Teams Channels

A lot of people have asked for “private channels” in Microsoft teams. Microsoft has stated publicly that they’re working on it; there’s even a page in the documentation all ready for when it comes along!

In the meantime, a question came up about using SharePoint permissions to restrict the level of access to channel files. Recall that every Team has a SharePoint site, and the files in the Files tab land in a document library on that site. Each Teams channel gets a folder in that site. (For more details see this article by Matt Soseman.)

So is it possible to make a “semi-private” channel by simply modifying the folder permissions in SharePoint? The idea is that while the conversation might be open, the files are only available to a subset of team members.

Continue reading

HTML Templates and CSS in SharePoint Framework Apps

“The time has come,” the Walrus said,
“To talk of many things:
Of template files, cascading styles,
And bundles made of strings,
And why SharePoint is boiling hot,
And whether pigs have wings.”

Like many SharePoint developers of late, I’ve been exploring the SharePoint Framework (SPFx), doing experiments, and porting code over to the new web part model. Something that perplexed me at first is how to handle HTML templates.

On the client side, I mostly work in AngularJS 1.x (Angular 2 isn’t ready for web parts yet since it only allows one instance of an app to run on a page at a time). And we Angular developers just love our templates! So how to manage them in the SPFx development environment? This article will show you how, and it will also clarify the mystery of CSS modules, which end up being related to HTML templates.

Continue reading

How to read information in a SharePoint Person field via the REST API

A colleague of mine recently had a challenge reading data out of a SharePoint person field via REST and then rendering it in AngularJS. As it turns out, I had the same challenge recently and found the solution … so here it is!

If you simply read the person field, you’ll end up with the user ID, which isn’t too helpful. The key is to use the OData $expand option to join the user ID to the user information (stored in a hidden list in every site collection). Here’s a sample.

$http.get("https://<servername>/sites/doccenter/" +
            "_api/web/lists/GetByTitle('Documents')/items?" +
           "$select=Title,Customer,FileLeafRef,FileRef,UniqueId,Modified," +
                "Author/Name,Author/Title" +
            "&$expand=Author/Id" +
           "&$filter=Customer eq '" + item.CustomerName + "'" +
.then(function (response) {
    // Add the response data to the ViewModel
    vm.items =;
.catch(function (response) {
   vm.message = "The list of documents could not be retrieved";

Now here’s the view that renders the author’s name. Notice that the person’s attributes are properties within the person object (Author in this case…)

<div class="row site-grid-row" 
         ng-repeat="item in vm.items">
    <div class="col-xs-12 col-sm-7 col-md-6 col-lg-6">
    <div class="hidden-xs hidden-sm col-md-3 col-lg-3">
    <div class="hidden-xs col-sm-5 col-md-3 col-lg-3">
       {{item.Modified | date : 'medium' : '-0500'}}

I hope someone else finds this helpful!

Understanding Javascript Promises

I have to admit I found the concept of Promises difficult to grasp at first; once I understood, I’ve been looking for a good way to explain it to others. This article is my attempt to make Promises easy to understand through a simple metaphor.

Imagine you’ve entered a crowded restaurant. You force your way to the maître d’ and request a table, and are told there is a wait. “We’ll call your name when the table is ready,” she says. This is the equivalent of a “callback” function – the server (a restaurant server in this case) will call you (the client) back when your request is complete. Inevitably half the people in the room are named “Bob” and a crowded confusion ensues.

Continue Reading

Stretching the (HTML 5) Canvas: Fixing Aspect Ratio Problems

The Problem

I’m working in a web part that uses the HTML 5 <canvas> element, and I ran into a little problem. The web part is a “microsurvey” that asks a single question and, when the user clicks an answer, displays the results of the survey so far. For the results, I wanted to show a bar chart, and I thought it would be a fun opportunity to use the new HTML 5 canvas. The problem is that my chart was distorted; as you can see the text is too wide and looks like it came off an old dot matrix printer. Somebody stretched the canvas!

3-9-2015 6-28-46 PM

Continue Reading

How to: Display the name of the Windows user logged into your ASP.NET Site

This article is reposted from my old MSDN blog. Please post comments here as I am no longer able to publish or respond to them on MSDN. Thanks!

This is really pretty simple but I was surprised not to find it in any one blog posting. The following code retrieves the display name of the logged in user, such as “Bob German” (not “domain\username”). It’s easy to accidentally display the Application Pool account rather than the logged in user. Some articles said to turn on Impersonation, but that’s often a bad idea for other reasons. This is what worked for me just now:

string username = &amp;quot;&amp;quot;;
IPrincipal userIdentity = HttpContext.Current.User;
PrincipalContext context =
    new PrincipalContext(ContextType.Domain);
UserPrincipal userPrincipal =
        (context, userIdentity.Identity.Name);
if (userPrincipal != null)
    username = userPrincipal.DisplayName;

I hope this helps someone; thanks!