SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've implemented my ListFieldIterator to change the way field controls rendered. I'd like to change the behaviour of form depending on the item content type, but any attempts to determine ContentTypeId from the code returns wrong result.



are always return


(which is invalid content type id)

There's a property LoadContentTypes in SPContext class, but setting it TRUE for SPContext.Current or FieldIterator.ItemContext makes no difference.

What am I doing wrong?

share|improve this question
up vote 2 down vote accepted

In addition to the method with determining ContentType in custom ListFieldIterator from query string, ItemContext contains property ContentType. But this property is internal and therefore could not be used directly in custom ListFieldIterator implementation.

Below is presented wrapper for retriving ContentType based on corresponding property for SPContext (Reflection is used here)

        private SPContentType CurrentContentType
            get {
                var ct = typeof(SPContext).GetProperty("ContentType", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ItemContext, null) as SPContentType;
                return ct;

Using CurrentContentType property, content type could be determined in custom ListFieldIterator implementation.

share|improve this answer
Thanks a lot! Your solution actually the best one, because it allows to determine content type even if it isn't specified in query string. – Leff Jan 23 '13 at 12:18
I agree and glad that was able to help :) – Vadim Gremyachev Jan 23 '13 at 13:18

The only way I found to determine content type in this case is to analize HTTP query string:

new SPContentTypeId(this.Context.Request.QueryString["ContentTypeId"])
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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