1

I have created through Visual Studio a Content Type that inherits from Item and a custom list using this content type. What I would like is to remove the item content type that appears when creating a new item.

More precisely, this option here:

enter image description here

Any way to achieve this through Visual Studio so it appears in every instance?

2

Go to the List Settings page for your list, scroll down to the Content Types section, click on the link 'Change new button order and default content type', and on the following page uncheck 'Visible' for the Item content type. It will no longer be visible in the new item ribbon menu.

  • Thank you Dylan, but I want to achieve this programmatically so this can be reflected in any instance of that list. I will update this questions with this – Gonzalo Mar 3 '15 at 20:00
1
 using (SPSite site = new SPSite("http://pbmossdev"))
{
    using (SPWeb web = site.OpenWeb())
    {
        string listName = "New List";
        string listDescription = "Test content types on lists";

        Guid listId = web.Lists.Add(listName,
            listDescription,
            SPListTemplateType.GenericList);

        SPList myList = web.Lists[listId];

        myList.ContentTypesEnabled = true;
        myList.ContentTypes.Add(web.AvailableContentTypes["Contact"]);//Replace with your custom content type
        myList.ContentTypes.Delete( myList.ContentTypes["Item"].Id  );

        myList.Update();

    }
}
  • Where would this be placed? – Gonzalo Mar 3 '15 at 20:17
  • In feature event receiver on feature activated.For information on how to create list on feature activated, refer this link: stackoverflow.com/questions/19548874/… – 404 Mar 3 '15 at 20:21
  • Also, if you do not want to change settings by code, you can do list settings as per @Dylan suggested, then save it as template and add to solution. Then, in feature receiver, instead of SPListTemplateType.GenericList, create list from this template which you have saved. – 404 Mar 3 '15 at 20:23
  • Thank you. I will try this alternative and let you know the outcome! – Gonzalo Mar 4 '15 at 16:49
  • Actually, I was just looking at the code, and what I need is that any custom list with a particular content type, does not have content type Item available. Is a feature the right way to go? – Gonzalo Mar 4 '15 at 17:09
0

Would you like a PowerShell solution for your query? Once you deploy your wsp package you can run a Tiding up PowerShell script which can take care of all such requirements. Make a PowerShell script file, and write all the functional logic which you want to achieve on top of wsp package. Removing content type can be one of it.

Below is a server side PowerShell script which will remove ITEM content type from the list

    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    $web = Get-SPWeb "UrlOfYourSite"
    $list = $web.Lists["YourListName"]
    $ctToRemove = $list.ContentTypes["Item"]
    if($ctToRemove)
    {
        Write-Host "Removing Item content type"
        $list.ContentTypes.Delete($ctToRemove.Id)
        $list.Update()
        $Web.Dispose()
    }
    else
    {
        Write-Host "Item content type do not exists in list"
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.