Export (0) Print
Expand All

SPFolder.ContentTypeOrder Property

Windows SharePoint Services 3

Gets an ordered list of content types.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public IList<SPContentType> ContentTypeOrder { get; }

Property Value

Type: System.Collections.Generic.IList<SPContentType>
A System.Collections.Generic.List<SPContentType> object that represents a list of content types.

ExceptionCondition
InvalidOperationException

The folder’s ParentListId property returns an empty GUID. This happens when the folder is not part of a list. The value of the ContentTypeOrder property has meaning only in the context of a list.

This property returns a list of SPContentType objects. The sequence of objects in the list determines the order in which content types are listed in the user interface, such as on a Sharepoint list’s New menu or on the List Settings page.

The default order is the same as the order of objects in the collection returned by the ContentTypes property of the folder’s parent list. You can create a custom order by setting the folder’s UniqueContentTypeOrder property. To return to the default sequence, set the UniqueContentTypeOrder property to a null value.

The following example is part of a console application that examines each folder in a site’s folder collection. If a folder belongs to a list, the application prints the folder’s current content type order to the console.

SPSite site = new SPSite("http://siteUrl");
SPWeb web = site.OpenWeb();
System.Collections.Generic.IList<SPContentType> currentOrder = new System.Collections.Generic.List<SPContentType>();

foreach (SPFolder folder in web.Folders)
{
    if (folder.ParentListId != Guid.Empty)
    {
        // Get the current content type order
        currentOrder = folder.ContentTypeOrder;

        // Print the content type order 
        Console.WriteLine("Content type order for the " + folder.Name + " folder:");
        foreach (SPContentType ct in currentOrder)
        {
            Console.WriteLine(ct.Name);
        }
        Console.WriteLine();
    }
}

// Clean up.
web.Dispose();
site.Dispose();

Community Additions

ADD
Show:
© 2014 Microsoft