36

I'm developing a solution in SharePoint 2010 that deploys a content type. I've now made a change to the content type and want to delete all its old references, remove it, and redeploy.

Unfortunately when I try to delete the content type, either from the UI or code, I get the error:

SPException: The content type "XYZ" is part of an application feature.

I've tried the following steps:

  • deleted all lists referencing the content type
  • emptied the site level and site collection level recycle bin
  • deactivated the feature from the UI and command-line using -force
  • uninstalled the feature from the command-line using -force
  • uninstalled the solution
  • reinstalled the solution and performed all of the above again

Still it will not be moved!

Any ideas?

3
  • does the content type have a list definition and list instance associated with it in your feature, or is it only a content type?
    – djeeg
    Apr 13, 2011 at 5:35
  • Not a production solution, but glad you were able to clear up your issue!
    – Tom Resing
    Apr 13, 2011 at 22:11
  • 3
    Abandoning the problem because it happened in dev is not a solution for the original question May 6, 2013 at 6:45

9 Answers 9

27

Content Types deployed via a Feature get a flag IsFromFeature in the DB. I don't know of any way to remove this flag by code. When the feature the content type was deployed with is retracted and the content type is not removed upon retraction - you will have the problem as you stated "content type is part of feature[...]".

Besides re-activating the feature you installed the content type with and deleting it then, I can only think of doing this via the DB. Just like you stated - this content type will have no usages (SPContentTypeUsage.GetUsages()), it just has this darn flag in the database.

A writeup about this orphaned content type you can find here: How To Delete an “Orphan” Content Type?, though it is for SP2007.

When running into this problem, I usually try to resolve the problem by re-activating the feature the CT came with.

3
7

You should be able to delete any feature content type (XY) following these steps:

  1. Delete any content type that derives from XY (you can find it using powershell or in SQL in table ContentTypes)
  2. Delete any item with content type XY
  3. Remove content type XY from all lists or delete the lists (these are ContentTypeUsages)
  4. Empty ALL recycle bins (there are 3)
  5. Deactivate feature with content type XY FROM UI (definitely NOT with the -FORCE parameter) If you don´t have the feature anymore, create dummy feature, with fake CT - put the right content type ID and Name, other attributes doesn't metter, even the FieldRefs node doesn't matter.
  6. Check the site content types, if XY remains there, some of the steps 1,2,3 or 4 were not completed successfully.
1
  • I've found this to be true. if you deactivate the content type feature AFTER ensuring all content types (and recycle bin copies) are deleted, the content type will dissapear. Jun 2, 2017 at 16:32
5

Did you verify that your custom content type is not being used as a base type for another content type that is still being used? If so, that type and all references to it must go as well.

Lastly, did you tie a Page Layout to that content type? If so, all pages based on that layout must be deleted before you can delete the layout.

1
  • 1
    It's not a base type, apart from being used in that list which I deleted. It's not being used for page layouts. Good ideas though, thanks!
    – Alex Angas
    Apr 13, 2011 at 3:08
4

I just ran into the same problem with a Content Type deployed declaratively(i.e. using elements.xml) as part of a farm solution. Here are a couple things I noticed.

  • I only encountered the problem when the SPContentType's FeatureId property was set to a value other than the empty GUID(i.e. 00000000-0000-0000-0000-000000000000) However, when the FeatureId property was set to the empty GUID, I did not encounter the problem; when the content type's associated feature was disabled/deactivated then the content type would be deleted (note: I still received the error if I tried to delete the content type while the feature was enabled)
  • The only time that the FeatureId was set to a value other than the empty GUID was when I set Inherits="FALSE" in the ContentType element. I didn't test the scenario when you don't specify the Inherits attribute, but according to the documentation, it may exhibit different behavior.

So, setting Inherits="TRUE" in the ContentType element may help you avoid this issue. I was unable to find any way to solve the problem using the api once the FeatureId is set to a value. Perhaps modifying the database, as suggested in a different answer, may fix it.

EDIT: I did test the scenario where the Inherits property is not specified and it seems to result in the same behavior as setting Inherits="FALSE".

2

Did you already read the "Deleting Content Types" article on MSDN? It guides you on a programmatic approach for detecting usage and deleting content types. http://msdn.microsoft.com/en-us/library/ms453791.aspx

As a last resort you could do a couple of selects (yeah I know you are not supposed to do that, so dont tell anyone if you mess it up ;-)) on the ContentTypeUsage table to find out if you missed a reference or the CT is somehow orphaned. In this case you would set the IsFromFeature to 0 which should allow you to delete the CT using the GUI. DO THIS AT YOUR OWN RISK :-O http://blog.thekid.me.uk/archive/2008/11/03/a-tip-when-looking-at-the-sharepoint-content-db.aspx

Oh and Dave is spot on with contenttypebinding, most people forget to check that :-)

3
  • Yes tried that and got the same error unfortunately.
    – Alex Angas
    Apr 13, 2011 at 7:15
  • so you have NO references to it in ContentTypeUsage ? Apr 13, 2011 at 7:31
  • Nope :(
    – Alex Angas
    Apr 13, 2011 at 7:33
1

Best way to delete content types

  1. Save the site as template, save it to a physical location
  2. Open Visual Studio, create new project under sharepoint- Import SharePoint Solution Package
  3. Naming convention for solution to be very small like ST
  4. Save the project in folder with small file path as C:\HB
  5. In the solution explorer in the project under content types, remove the unwanted contentTypes
  6. Save the Project, Build & Deploy either from VS or Powershell
  7. The content types are deleted without removing the feature :)
1

Reviving an old thread with a new solution for a still existing problem.

I don't think I have to enphasize how updating DB directly is a no-no, but, for a dev environment, works like a charm.

--update content type isFromFeature Flag to allow deletion

--read
SELECT * FROM DBNAMEHERE_RMC.[dbo].[ContentTypes] WHERE Definition like '%CTNAMEHERE%'

--write
--UPDATE DBNAMEHERE_RMC.[dbo].[ContentTypes] SET IsFromFeature = 0 WHERE Definition like '%CTNAMEHERE%'

Source

Remove Orphaned Content Types in SharePoint 2010 That Are Associated With a Feature.

0

Try this: Use Visual Studio to deploy a feature with a content type having the same GUID as the one you want to remove. Set the conflict action on the deployment to NONE so that if something already exists it will just ignore it.

Set the project to retract after debugging. Debug the solution and confirm that the item is there. Now, stop debugging and see if the item goes away. This worked for me.

0

To delete the content type which was published from a feature, you must redeploy solution containing THE SAME ID TO THE DEPLOYED CONTENT TYPE.

  1. Activate the feature which deploy content type
  2. Deactivate the feature

Normally, the content type should disappear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.