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:

Cls
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”)
$ColumnDefaults.Update()

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 www.MicrosoftVirtualAcademy.com

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: http://www.timeanddate.com/worldclock/

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);
            clientContext.ExecuteQuery();
            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: https://skydrive.live.com/?cid=743e7abd51ea3851&id=743E7ABD51EA3851%21757&authkey=!ACIqsQhqXZipXcY (Movember.zip)

Updates and alternative insights can be tracked here: http://social.technet.microsoft.com/wiki/contents/articles/16353.sharepoint-2013-best-practices-working-with-connection-strings-in-auto-hosted-sharepoint-apps.aspx

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 http://social.technet.microsoft.com/wiki/contents/articles/12438.sharepoint-2013-best-practices.aspx#Debugging

TechNet Wiki SharePoint 2013 Best Practices Page