using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ContentTypeTest
{
class Program
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://xxxxx"))
{
foreach (SPWeb web in siteCollection.AllWebs)
{
// Get the obsolete content type.
SPContentType obsolete = web.ContentTypes["Leave Request"];
// We have a content type.
if (obsolete != null)
{
IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(obsolete);
// It is in use.
if (usages.Count > 0)
{
Console.WriteLine("The content type is in use in the following locations:");
foreach (SPContentTypeUsage usage in usages)
Console.WriteLine(usage.Url);
}
// The content type is not in use.
else
{
// Delete it.
Console.WriteLine("Deleting content type {0}...", obsolete.Name);
//webSite.ContentTypes.Delete(obsolete.Id);
}
}
// No content type found.
else
{
//Console.WriteLine("The content type does not exist in this website.");
}
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}