Imagine Think Create Share

Office | SharePoint | Search | Architecture | Stuff
Blog - Title

November, 2010

  • Imagine Think Create Share

    Delete a Builtin ContentType from the list - Item, Document ... SPBuiltInContentTypeId

    • 0 Comments

    Hi,

    In order to delete a out of the box content type from a list/Library  (item, document, etc..), you need to delete it from name as the associated Id in the list is a child of the site contentType.

    When you add a site content type to a list or library, SharePoint Foundation makes local copies of any columns that are referenced by the content type and adds them to the list's fields

    So to delete for example the item content type, you will need to:

    SPContentTypeId ListitemContentTypeId = list.ContentTypes[web.ContentTypes[SPBuiltInContentTypeId.item].Name].Id;
    list.ContentTypes.Delete(ListitemContentTypeId);

    Namaste!

  • Imagine Think Create Share

    Order List Content Types or Solve your "Specified argument was out of the range of valid values.Parameter name: id / value"

    • 0 Comments

    Hi,

    You have tried to order the content type list for a list and you are not able to do it. You always receive an error when UniqueContentTypeOrder is set. Take a look at the following steps in order to resolve the issue.

    SPFolder folder = list.RootFolder;
    IList<SPContentType> contentTypeCollection = new List<SPContentType>();

    contentTypeCollection = folder.ContentTypeOrder;
    contentTypeCollection.RemoveAt(0);
    folder.UniqueContentTypeOrder = contentTypeCollection;
    folder.Update();


    in the code above the rootfolder for the list is updated with a new content type collection without the first item. This will update fine the list. the differences:

    • You cannot create the list, add content types and change the order in the same step. First create list, add content types, update and later change the order with a fresh list reference.
    • The contentTypeCollection must be a list qirh the list contentType references, NOT web or site reference.
      • Do not contentTypesCollection.Add(web.ContentTypes[new SPContentTypeId(ct)]);
      • DO contentTypesCollection.Add(list.ContentTypes[new SPContentTypeId(ct)]);

    Bye!

Page 1 of 1 (2 items)