Sometimes you may be getting this error message when you think you shouldn’t be getting it:
Content Type is still in use at Microsoft.SharePoint.Library.SPRequestInternalClass.SetListContentTypes(String bstrUrl, String bstrListName, String bstrXML, String bstrSqlPrefix, String bstrSqlSuffix)
at Microsoft.SharePoint.Library.SPRequest.SetListContentTypes(String bstrUrl, String bstrListName, String bstrXML, String bstrSqlPrefix, String bstrSqlSuffix)
This could happen either when you are trying to delete the content type via the SharePoint GUI or from your custom code. You may be thinking that this is incorrect, however have you considered this:
1) Actually you may not see documents that are using the content type because you don’t have rights to. SharePoint 2007 has item level security settings. So check all the documents in the list with an account that has full control (e.g. site collection admin).
2) 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.
3) If the list has the ForceCheckOut flag enabled, then someone may have just added a document and may have not yet pressed “Check In” or may have pressed “Cancel” on the EditForm page. In such a case the document will be added to the list with version 0.1 but will be checked out to that user and will not show up for anyone else (including site collection admins). Actually even if you check through code the SPList.Items with elevated privileges account you will still not be able to see this item if it is not checked out to the elevated account.
One way to detect whether you are having such a “hanging” document is to check the SPList.ItemCount property and see if its value is the same as SPList.Items.Count. If they are different then you may have this type of “hanging” documents in your list. The ItemsCount seems to be stored in an internal array of list properties and counts all the items in the list, while SPList.Items will return only the items you can see.
public int ItemCount
return (int) this.m_arrListProps[20, this.m_iRow];