Sunday, February 27, 2011

Hide content types of a list in share point programmatically.(Hide the content types in new button drop down in the share point list)

In share point list contains the content types. The available content types will be available on the new button drop down list. Programmatically we can hide the content types available in the list. The code shown shown below.
//hide the content types of a list in the new button drop down list 

private static void HideContentType(SPList list)
{
  string contentTypeName = string.Empty;
  SPContentType contentType;
  Console.WriteLine("enter the name of the content type to hide");
  contentTypeName = Console.ReadLine();
  if (!string.IsNullOrEmpty(contentTypeName))
  {
    contentType = list.ContentTypes[contentTypeName];
    if (contentType != null)
    {
      contentType.Hidden = true;
      Console.WriteLine("content type of the list is hiden");
    }
    else
    {
      Console.WriteLine("content type is not exists for the current list");
    }
  }
  else
  {
    Console.WriteLine("content type name should not be null or empty");
  }
}


In the above code take content type what we need to hide as input. Then check the list if the list have the content type or not. If the list contains the content type then make hidden property of the content type as true.

Hope this will help you.

Share this