Best way to find where content type is in use

I just happened across a handy class within the SharePoint object model which allows finding where a content type is currently in use within a site much quicker than using the custom code I had previously been using.  This would be handy when unable to delete a content type because it is in use, or if we simply want to know if a content type is in use somewhere within our SharePoint site.

Used to track available content types used throughout a site collection.



private void GetContentTypeUsage(string ctypeId)
// get content type from supplied id
SPContentType ctype = SPContext.Current.Web.ContentTypes[new SPContentTypeId(ctypeId)]; 

  // get list containing all references
IList<SPContentTypeUsage> usageList = SPContentTypeUsage.GetUsages(ctype); 

  if (usageList.Count > 0)
for (int count = 0; count < usageList.Count; count++)
// do something

      // usageList[count].IsUrlToList;
// usageList[count].Id;
// usageList[count].Url;

I found the above information while looking at the link below detailing the Microsoft.SharePoint Namespace:

This entry was posted in SharePoint and tagged . Bookmark the permalink.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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