SPFolder.UniqueContentTypeOrder Property (Microsoft.SharePoint)
Sets or gets an ordered list of content types.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
Public Property UniqueContentTypeOrder As IList(Of SPContentType)
Visual Basic (Usage)
Dim instance As SPFolder
Dim value As IList(Of SPContentType)

value = instance.UniqueContentTypeOrder

instance.UniqueContentTypeOrder = value
C#
public IList<SPContentType> UniqueContentTypeOrder { get; set; }

Property Value

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

Exception typeCondition

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.

Remarks

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.

C#
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.

Example

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.

Visual Basic
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Console.WriteLine()

        Dim site As SPSite = New SPSite("http://siteUrl")
        Dim web As SPWeb = site.OpenWeb()
        Dim list As SPList = web.Lists("Test Library")

        ' Get the current order and print it to the console
        Dim currentOrder As System.Collections.Generic.IList(_
                Of SPContentType) = _
                New System.Collections.Generic.List(Of SPContentType)
        currentOrder = list.RootFolder.ContentTypeOrder
        Console.WriteLine("Old order:")
        For Each ct As SPContentType In currentOrder
            Console.WriteLine(ct.Name)
        Next

        ' Create a new order by reversing current order
        Dim newOrder As System.Collections.Generic.IList(Of SPContentType) =_
                        New System.Collections.Generic.List(Of SPContentType)
        For i As Integer = currentOrder.Count - 1 To 0 Step -1
            newOrder.Add(currentOrder(i))
        Next

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

        Console.WriteLine("New order:")
        For Each ct As SPContentType In list.RootFolder.ContentTypeOrder
            Console.WriteLine(ct.Name)
        Next

        ' Clean up
        web.Dispose()
        site.Dispose()

        Console.WriteLine()
        Console.Write("Press ENTER to continue...")
        Console.ReadLine()
    End Sub

End Module
C#
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...
See Also

Tags : incomplete


Community Content

PaulB
New button in list view
This list appears to manage the menu under the new button in the default list view.
Tags :

David S Rodrigues
How to use programatically
I had a difficult time trying to use this property to get rid of some content types from the New button. I finally figured it out with the following code. It works like a charm.

Dim newListItem As SPListItem

Dim newFolder As SPFolder

newListItem = spList.Folders.Add("", SPFileSystemObjectType.Folder, folderName)

newListItem("ContentType") = "Attribute"

newListItem("Title") = value

newListItem("NumberOfLevels") = levels

newListItem.Update()

newFolder = newListItem.Folder

Dim contenttypes As New List(Of SPContentType)

contenttypes.Add(spList.ContentTypes("Valid Value"))

newFolder.UniqueContentTypeOrder = contenttypes

newFolder.Update()


Badically, create a new list of SPContentTypes, add a content type from the ContentTypes property of the list and then assign that to UniqueContentTypeOrder.
Tags : code

bill_csharper
thanks!
Thanks David, that worked!
i struggled for hours to add a folder to a list;
the sharepoint documentation is worse than garbage, right down there with the trash documentation of the TFS API.
Tags :

Page view tracker