SharePoint Dragons

Nikander & Margriet on SharePoint

Setting default content type column values for a library via PowerShell

Setting default column values for content type columns, the equivalent of [Document Library] > Document Library Settings > Column Default value settings, was surprisingly hard to build in PowerShell. The main gotcha has to do with the fact that you can’t do this via the SPContentType type, instead, you have to do it via the more obscure MetadataDefaults type, located in the Microsoft.Office.DocumentManagement.dll. Here’s the script:

Write-Host “Initializing SharePoint PowerShell Environment”

$SnapIn = “Microsoft.SharePoint.PowerShell”
if ( get-pssnapin $SnapIn -ea “silentlycontinue”)
  Write-Host “Remove SharePoint snap-in” 
  remove-pssnapin $SnapIn
if ( get-pssnapin $SnapIn -registered -ea “silentlycontinue”)
  Write-Host “Add SharePoint snap-in” 
  add-pssnapin $SnapIn

Write-Host “Start Setting default value for content type column”

Add-Type -Path ‘c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Office.DocumentManagement.dll’
$ProjectWeb = Get-SPWeb -Identity “http://demosrv/sites/Wilmie”
$List = $ProjectWeb.Lists[“1. Project Management”]

$ContentType = $List.ContentTypes[“TestContentType”]

$ColumnDefaults = New-Object -TypeName Microsoft.Office.DocumentManagement.MetadataDefaults $List                 
$ColumnDefaults.SetFieldDefault($List.RootFolder, “TestColumn”, “TestValue from PS”)

Write-Host “End setting default value”

PowerShell/SharePoint Error

We got the error New-SPSite : Could not find file ‘C:\Users\Administrator\AppData\Local\Temp\1\k5hcoe1g.dll when running a PowerShell script that created a SharePoint site collection. In the end, it turned out the code was fine, we just had to close the PowerShell window and open it again. Weird error message, huh?

Removing Ugly GUIDs from Database Names

Great resource about SharePoint Databases

SharePoint DR

Interesting MS Learning Resource: The Virtual Academy!

Check out the MS virtual academy at

World Clock

Sometimes, you really need to see what time it is at any place in the world. This is our favy web site for doing this:

Working with Connection Strings in Auto-Hosted Apps

Richard diZerega has a really nice util method for working with connection strings in Auto-Hosted Apps in SharePoint 2013. It goes like this:

using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Data.EntityClient;
using System.Linq;
using System.Web;
using System.Web.Configuration;

namespace MovemberWeb.Util
    public class ConnectionUtil
        public static string GetEntityConnectionString(ClientContext clientContext)
            //try to get the connection string from from the clientContext
            clientContext.Load(clientContext.Web, web => web.Title);
            ClientResult<string> result = AppInstance.RetrieveAppDatabaseConnectionString(clientContext);
            string connString = result.Value;

            //if the connection string is empty, then this is debug mode
            if (String.IsNullOrEmpty(connString))
                connString = WebConfigurationManager.ConnectionStrings[“LocalDBInstanceForDebugging”].ConnectionString;

            //build an Entity Framework connection string
            EntityConnectionStringBuilder connBuilder = new EntityConnectionStringBuilder();
            connBuilder.Provider = “System.Data.SqlClient”;
            connBuilder.ProviderConnectionString = connString;
            connBuilder.Metadata = “res://*/MovemberModel.csdl|res://*/MovemberModel.ssdl|res://*/MovemberModel.msl”;

            //return the formatted connection string
            return connBuilder.ConnectionString;

You can get it here:!ACIqsQhqXZipXcY (

Updates and alternative insights can be tracked here:

People Picker Quick Tip

Use Fiddler to monitor web traffic using the People Picker. This will provide insight in how to use the people picker for custom development. Keep track of updates to this tip and other debugging tips at

TechNet Wiki SharePoint 2013 Best Practices Page