Share via


SPContentType.Hidden property

Gets or sets whether the content type is hidden on the list’s New menu.

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

Syntax

public bool Hidden { get; set; }

Property value

Type: System.Boolean
true if the content type is hidden on the list’s New menu; otherwise false.

Exceptions

Exception Condition
SPContentTypeReadOnlyException

The value of the ReadOnly property is true.

SPContentTypeSealedException

The value of the Sealed property is true.

Remarks

You can use this property to specify that a content type be hidden. Hidden content types are not displayed on the New menu for list views. Therefore, users cannot create new items of that content type from the list. The content type is still displayed everywhere else in the user interface.

Tip

To change the order in which content types appear on the New menu, set the UniqueContentTypeOrder property.

When you modify the value of this property, your change does not take effect until you call the Update() method. Calling this method commits all modifications to the content type definition back to the SharePoint database.

Examples

The following console application prevents one of the content types available in a document library from appearing on the library’s New menu.

using System;
using Microsoft.SharePoint;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("https://localhost");
            SPWeb oSPWeb = oSPSite.OpenWeb();

            // Hide a content type from the New menu on a list.
            SPList oList = oSPWeb.Lists["Custom Document Library"];
            SPContentType oContentType = oList.ContentTypes["Content Type Name"];
            if (oContentType.ReadOnly || oContentType.Sealed)
            {
                Console.WriteLine("Content type cannot be modified.");
            }
            else
            {
                oContentType.Hidden = true;
                oContentType.Update();
                Console.WriteLine("Content type is now hidden.");
            }

            oSPWeb.Dispose();
            oSPSite.Dispose();

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

See also

Reference

SPContentType class

SPContentType members

Microsoft.SharePoint namespace