Archive for March, 2010
If you are like me, you tend to deal with strange development nuances in the SharePoint environment. One of those nuances is trying to delete a content type that is in use. When I’m developing a solution that requires the creation of content types within the feature, I typically create that content type through code. That will work on the first deployment of the feature since it does not exist yet. On subsequent deployments, you will get an error that either the content type is in use (if you are trying to delete it before adding) or the content type already exists. One thing I do is disable the deletion/creation of the content type if I’m not making any changes to it on subsequent deployments. That will save a bit of development time. The second problem I get every so often is the “content type still in use” error when trying to delete a content type. I find this to happen if I am careless with removing items from a list, especially workflow tasks that are associated with a content type.
I found a decent SQL Script (below) on the interweb that displays all the instances of my content type in the SharePoint databases. In some cases, this will tell me where the “remnant” of the content type is and I can remove it. Other times, it will display something that I already removed and I’m stuck. If that happens, I first blow away the list where the content type was associated. If the list removal doesn’t work, I will delete the site collection and build a new one. (That is a luxury of having my own development VM.) I found that course of action to be quicker than trying to go through the database structure to find where to delete all instances of that content type.