0

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

Priya
  • 1,375
  • 8
  • 21
  • 45

1 Answers1

0

Make sure that all references are deleted and removed from all recycle bins as well.

For example, if a list references a content type is deleted it will be moved to the recycle bin and sharePoint still sees a reference. Delete from all recycle bins (end-user and site collection) and try again.

Ola Ekdahl
  • 1,484
  • 1
  • 11
  • 21