Feb 12

Content Type is still in use

Tag: Collaboration — February 12, 2010 @ 3:06 pm
Author:

C/D/H Consultant

More about C/D/H
Articles by

Working with technology, you are inevitably going to run across a task that seems simple, but 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 should have been a trivial task.

I went on to create the new content type; I re-classified content and then moved on to delete the old content type.

Picture 1

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

Picture 2

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 identify 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 publish a major version anytime you are changing the content type of an item!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>