Share via


SPFolder.ContentTypeOrder Property

Gets an ordered list of content types.

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

Syntax

Public ReadOnly Property ContentTypeOrder As IList(Of SPContentType)
    Get

Dim instance As SPFolder
Dim value As IList(Of SPContentType)

value = instance.ContentTypeOrder
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.

Exceptions

Exception Condition
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.

Remarks

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.

Examples

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.

Dim site As SPSite = New SPSite("http://siteUrl")
Dim web As SPWeb = site.OpenWeb()
Dim currentOrder As System.Collections.Generic.IList(Of SPContentType) = New System.Collections.Generic.List(Of SPContentType)

For Each folder As SPFolder In web.Folders

    If folder.ParentListId <> Guid.Empty Then

        ' Get the current content type order
        currentOrder = folder.ContentTypeOrder

        ' Print the content type order
        Console.WriteLine("Content type order for the " + folder.Name + " folder:")
        For Each ct As SPContentType In currentOrder
            Console.WriteLine(ct.Name)
        Next
        Console.WriteLine()

    End If

Next

' Clean up
web.Dispose()
site.Dispose()
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();

See Also

Reference

SPFolder Class

SPFolder Members

Microsoft.SharePoint Namespace