This documentation is archived and is not being maintained.

SPFolder.UniqueContentTypeOrder Property

Windows SharePoint Services 3

Sets or gets an ordered list of content types.

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

public IList<SPContentType> UniqueContentTypeOrder { get; set; }

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. Setting or getting the value of the UniqueContentTypeOrder property has meaning only in the context of a list.

ArgumentOutOfRangeException

You are attempting to set the property with an empty list. The list must contain at least one content type.

The value returned by the UniqueContentTypeOrder property is identical to the value returned by the ContentTypeOrder property. Setting the UniqueContentTypeOrder property also sets the ContentTypeOrder property. Both properties determine the sequence 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.

You can reset the folder’s content type order to the default order by setting the UniqueContentTypeOrder property to a null value, as in the following code snippet.

list.RootFolder.UniqueContentTypeOrder = null;

TipTip

You can hide a content type by setting the UniqueContentTypeOrder property with a list that omits the content type that you wish to hide.

The following example is a console application that first prints the current content type order to the console, then reverses the content type order, and finally prints the new content type order to the console. The application assumes the existence of a site with a list named “Test Library” that contains one or more content types.

using System;
using Microsoft.SharePoint;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();

            SPSite site = new SPSite("http://siteUrl");
            SPWeb web = site.OpenWeb();
            SPList list = web.Lists["Test Library"];

            // Get the current order and print it to the console
            System.Collections.Generic.IList<SPContentType> currentOrder =
                      new System.Collections.Generic.List<SPContentType>();
            currentOrder = list.RootFolder.ContentTypeOrder;
            Console.WriteLine("Old order:");
            foreach (SPContentType ct in currentOrder)
            {
                Console.WriteLine(ct.Name);
            }
            Console.WriteLine();

            // Create a new order by reversing current order
            System.Collections.Generic.IList<SPContentType> newOrder =
                      new System.Collections.Generic.List<SPContentType>();
            for (int i = currentOrder.Count - 1; i > -1; i--)
            { 
                newOrder.Add(currentOrder[i]);
            }

            // Set the new order and update folder
            list.RootFolder.UniqueContentTypeOrder = newOrder;
            list.RootFolder.Update();

            // Display the new current order
            Console.WriteLine("New order:");
            foreach (SPContentType ct in list.RootFolder.ContentTypeOrder)
            {
                Console.WriteLine(ct.Name);
            }

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

            Console.WriteLine();
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}

When run against a list with two content types, Presentation and Proposal, the application prints the following output to the console.

Old order:
Presentation
Proposal

New order:
Proposal
Presentation

Press ENTER to continue...
Show: