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 Property Hidden As Boolean
Get
Set
Dim instance As SPContentType
Dim value As Boolean
value = instance.Hidden
instance.Hidden = value
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.
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Console.WriteLine()
Dim oSPSite As SPSite = New SPSite("http://localhost")
Dim oSPWeb As SPWeb = oSPSite.OpenWeb()
' Hide a content type from the New menu on a list.
Dim oList As SPList = oSPWeb.Lists("Custom Document Library")
Dim oContentType As SPContentType = oList.ContentTypes("Content Type Name")
If (oContentType.ReadOnly Or oContentType.Sealed) Then
Console.WriteLine("Content type cannot be modified.")
Else
oContentType.Hidden = True
oContentType.Update()
Console.WriteLine("Content type is now hidden.")
End If
oSPWeb.Dispose()
oSPSite.Dispose()
Console.WriteLine()
Console.Write("Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
Console.WriteLine();
SPSite oSPSite = new SPSite("http://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();
}
}
}