I want to delete content type programmatically on feature deactivation. I've wrote the code to perform deletion:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPWeb webSite =(SPWeb)properties.Feature.Parent)
{
webSite.AllowUnsafeUpdates = true;
// Get the obsolete content type.
SPContentType obsolete = webSite.ContentTypes["Examples8888 - CT1"];
// We have a content type.
if (obsolete != null)
{
IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(obsolete);
// It is in use.
if (usages.Count <= 0)
{
obsolete.Delete();
// Delete it.
Console.WriteLine("Deleting content type {0}...", obsolete.Name);
webSite.ContentTypes.Delete(obsolete.Id);
}
}
}
});
But it gives me error :
The content type is part of an application feature.
This content type is not being used anywhere still I am not able to delete it.
Is there any way to deal with this error?
Thanks, Priya