Control the Content Types in the New menu via code

using System;
using Microsoft.SharePoint;

namespace Test
    class ConsoleApp
        static void Main(string[] args)

            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)

            // 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--)
// Set the new order and update folder
            list.RootFolder.UniqueContentTypeOrder = newOrder;

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

            // Clean up.

            Console.Write("Press ENTER to continue...");


Another One:
1    private void SortContentTypes(SPList docLibrary)
2    {
3        IList<SPContentType> currentOrder = docLibrary.RootFolder.ContentTypeOrder;
4        List<SPContentType> newOrder = currentOrder.ToList<SPContentType>();
5        newOrder.Sort((x, y) => (x.Name.CompareTo(y.Name)));
6        docLibrary.RootFolder.UniqueContentTypeOrder = newOrder;
7        docLibrary.RootFolder.Update();
8    }



This entry was posted in SharePoint 2010, Visual Studio 2010. Bookmark the permalink.

One Response to Control the Content Types in the New menu via code

  1. Click here. says:

    Heya i’m for the first time here. I found this board and I find It really useful &
    it helped me out a lot. I hope to give something back and help oghers like you helped me.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s