Problem is I am trying to update a content type (created within a list definition, going into a new list instance) and it is not liking the ID I pass in code. I tried passing JUST the child ID, parent & child, and full (base, parent, child) ID. All of these result in various errors (object reference error and format error).

I am updating in a seperate feature from the one that creates the list definition and new content type.

Why is this giving me trouble? Here is a code snippet.

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
        using (SPSite spSite = new SPSite("site"))
            using (SPWeb web = spSite.OpenWeb())
                SPField field = web.Fields[new Guid("e93f5414-1486-481e-842d-696df0ff9ce6")];
                field.Group = "newAnimals";

                SPContentType cType = web.ContentTypes[new SPContentTypeId("CE2744E3BAEA4734B2333D043AA5DD2C")];
                cType.Description = "Super cool content type";

Again...this is at the DEFINITION level so I want to make one update to the content type the definition is implementing and have that change pushed to ALL content types being used within ANY list implementing this particular definition.

I do not want to do this via CAML, I am looking for the programmatic method.


1 Answer 1


Your Content Type Id is in wrong format:

Content Type IDs

Isn't it maybe: 0x0100CE2744E3BAEA4734B2333D043AA5DD2C (if parent type is item)


By using SPContentTypeCollection.BestMatch Method it is possible to avoid 'confusion' of what is the right ContentTypeId.

Searches the collection and returns the content type identifier (ID) that is the nearest match to the specified content type ID.

// id can be parent or even base content type
SPContentTypeId matchId = web.ContentTypes.BestMatch(id);
SPContentType cType = web.ContentTypes[matchId];

About two feature issue:

If one feature handles creation and another handles update then it is vital to activate them in right order. That is most likely your problem - you are trying to make update on Content type that still doesn't exist. Some more info on this issue:

To make things simple: if you want to be sure make the third (master) feature which will activate other features in right order.

Another addition

Since it is list content type you are after for you need to use SPList.ContentTypes instead of SPWeb.ContentTypes.

  • I specified the following in the original question "I tried passing JUST the child ID, parent & child, and full (base, parent, child) ID"
    – dbobrowski
    Sep 28, 2011 at 16:44
  • But you provided invalid code. new SPContentTypeId("CE2744E3BAEA4734B2333D043AA5DD2C") will fail Also CT is originally created in web you are reffering to (SPSite("site")) ? Sep 28, 2011 at 16:48
  • ......ok........ here you go: SPContentType cType = web.ContentTypes[new SPContentTypeId("0x0100CE2744E3BAEA4734B2333D043AA5DD2C")]; ALSO fails... and yes, the content type was created in the site collection I am passing as a parameter.
    – dbobrowski
    Sep 28, 2011 at 16:56
  • Since you provided some additional info in comments I have updated my answer. I am not magician to instantly provide solution so it is vital to include all possible info (in reasonable limits) to avoid guessing (as my original answer was) Sep 28, 2011 at 19:48
  • Apologies for getting frusterated, I thought the same as your last post and was fiddling around with activation order and I still seem to have the same issue. It just cannot find the content type by any ID I pass it. Also, activating a feature by the ID in the feature manifest (via code) fails - saying no feature can be found.
    – dbobrowski
    Sep 29, 2011 at 13:58

Your Answer

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

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