Compare Content Types in SharePoint List

Standard

Did you try to get a content type attached to list by its Id? for example you need to add a condition if a list item is Folder content type

I tried, it was simple but tricky because it seems to have a new ID inherited from the original content type so you must get the item content type first then compare its Parent with the Content type you need.

Here is an example to know if the current item is Folder content type or not (Folder content type has Id = 0x0120) :

If you use the following code it will give false although the content type is folder type

item.ContentType.Id == new SPContentTypeId(“0x0120”)

you have to use the following code to make it work

item.ContentType.Id.Parent == new SPContentTypeId(“0x0120”)

Advertisements