Content Type is still in use

27Jan10

Working with technology, you are inevitably going to run across a task that seems so simply, when you still can’t do what you wanted to do 10 minutes later, will leave you questioning your sanity.

I came across such a problem when updating a set of custom content types for a client.  One of the content types was seldom used and we wanted to re-classify any existing items of that type to another new content type, then delete the deprecated content type.

With only four items  of the old content type, this was a simply enough task.  The new content type was created, I re-classified content and then moved on to delete the old content type.

When I tried to delete it from the document library, I received the “Content Type is still in use” error.

Convinced that I had re-classified my content, I double and triple checked.  I was right; all items of the old content type were not of the new.  Through this testing, I came across an interesting piece of T-SQL that queries a DB to identity all places where a content type is used.

DECLARE @ContentTypeName nvarchar(128)

SET @ContentTypeName=’Document’

SELECT w.Title AS [Web Site], w.FullUrl AS [Web Url], al.tp_Title AS [List Title], ct2.* FROM ContentTypes ct1 JOIN ContentTypes ct2 ON LEFT(ct2.ContentTypeId, Len(ct1.ContentTypeId))=ct1.ContentTypeId LEFT OUTER JOIN dbo.ContentTypeUsage ctu ON LEFT(ctu.ContentTypeId, Len(ct2.ContentTypeId)) = ct2.ContentTypeId LEFT OUTER JOIN dbo.AllLists al ON ctu.ListId = al.tp_Id AND ctu.WebId=al.tp_WebId LEFT OUTER JOIN dbo.Webs w ON al.tp_WebId = w.Id WHERE ct1.ResourceDir=@ContentTypeName

Reference: http://social.technet.microsoft.com/Forums/en/sharepointadmin/thread/0a558f4f-cd1e-4432-85bb-caaa3a3b57ae

The T-SQL code confirmed what I already knew.  Yes, the only place where the content type was used was in the library by virtue of being added as a content type.

I first tried disabling and re-enabling content type management at the library, no luck.

I then tried an IIS reset, no luck.

Then I came across the following article which made my error so obvious that a slap in the face would have been more subtle.

Reference: http://hristopavlov.wordpress.com/2008/06/24/content-type-is-still-in-use/

As Hristo points out, just because I don’t have any current versions using it, it doesn’t mean that I didn’t have any previous minor versions using the old content type.

“If the list allows both minor and major versions and if any of the documents in the list is a minor version, but also has an existing previous major version (i.e. published version), then SharePoint will refuse to delete the content type if it is used by this last major version, even if the latest minor version is not using it.  I don’t have an explanation about why it is doing it, but this is how it works. It seems that you will need to check in a major version if you want to remove the content type in this case.”

Sure enough, when I re-classified my items, I only published a minor version.  To resolve this, simply publish a major version of the affected items or simply publish a major version anytime you are changing the content type of an item!



One Response to “Content Type is still in use”

  1. Fantastic! been searching high and low. your sql will be added to my ‘go to’ library!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.