blog.scoreman.net

Don’t use Linq on collections in DocumentSetTemplate

If you ever find yourself working with document sets through the SharePoint API, don’t use Linq on the Collections in DocumentSetTemplate. Even though they implement IEnumerable<T> they have not wired everything up internally so you will get NullReferenceException (Object reference not set to an instance of an object) when using any Linq statement on them. This applies to AllowedContentTypes, DefaultDocuments, SharedFields and WelcomePageFields.

You can easily reproduce this by running this code:

var ct = web.ContentTypes["Document Set"];
var template = DocumentSetTemplate.GetDocumentSetTemplate(ct);
template.AllowedContentTypes.Any();

Hopefully this will be fixed some day in the API

Leave a Reply