Friday, November 6, 2009

How To Delete an “Orphan” Content Type?


I created a set of content types from a feature and after the installation, activation of this feature, I used (in list or document libraries) all content types contained in this feature but one, called CT1 for instance

After a while, I wanted to remove the never used content type, so I modified the feature, removed the content type CT1 from it, reinstalled the feature.

The content type CT1 was still in the content types list! Ok, no problem, from the UI I click on delete this content type, and…


The content type "CT1" is part of an application feature.

What a message! I removed it from the feature, but still, I have this error. I googled a lot and with the help of Vincent Rothwell I finally found a solution, not Microsoft allowed, but efficient!


First, I checked if the content type was not used somewhere in a site (see Vincent Rothwell article)

Then I went to the DB and in the ContentTypes table, you can filter the CT you want with:

      ,sys.fn_varbintohexstr([ContentTypeId]) as CT
  FROM [SharePoint - 27235].[dbo].[ContentTypes]
where (sys.fn_varbintohexstr(ContentTypeId) LIKE '0x0101EF0201%')

Because I defined the CT, I knew the ContentTypeId. And I used sys.fn_varbintohexstr() because the ContentTypeId is of type tContentTypeId which is a varbinary(512)

In the result, you can see the column IsFromFeature set to 1. This means your CT belongs to a feature
image So one solution was to change the value of IsFromFeature to 0, in order to “fake” SharePoint.

Update [SharePoint - 27235].[dbo].[ContentTypes] set [IsFromFeature] = 0 where (sys.fn_varbintohexstr(ContentTypeId) LIKE '0x0101EF0201%')

Then I could delete the content type CT1 directly from the UI!


Jon Badgett said...

You can't really call this a solution, as directly modifying the db is explicitly prohibited if you want to maintain Microsoft support of the SharePoint product. I'm still looking for a way to get rid of these... Perhaps the object model could let you modify these properties?

Antoine Pichot said...

You're right, but you also assume there is no bug in SharePoint :-)
For me these missing id's are the consequence of a bug un SharePoint. Normally, when the error management is well done, such bad entries never exist in the DB. That's why there is no other possiblities (even with the object model) to remove these entries than removing them directly from the DB.

Unknown said...

THanx this worked for me!

Scott said...

Brilliant. Allowed me to correct a content type error for a MOPS 2007 upgrade to 2010. I was stuck on the sql for specifying the exact rows by contentTypeId - this was the ticket. Thanks!

Anonymous said...

"Update [SharePoint - 27235].[dbo].[ContentTypes] set [IsFromFeature] = 0 where (sys.fn_varbintohexstr(ContentTypeId) LIKE '0x0101EF0201%')"

This Amount to database editing , which will put your database in to Unsupported state ,

Anonymous said...

Very good blog poѕt.I certainly love this site. Keep it up!

my ѡeblog: vegetable smoothie diet -,

Affiliate Rookie said...

Excellent!!! This has helped me a great deal. Thank you for writing this!