Как определить тип элемента Тип содержимого в форм-управлении (например, полевой итератор)?

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/57298

Вопрос

Я реализовал мой список файлафильдер, чтобы изменить отображение полевых элементов управления. Я хотел бы изменить поведение формы в зависимости от типа содержимого элемента, Но любые попытки определить contenttypeid из кода возвращает неправильный результат.

ListFieldIterator.ListItem.ContentTypeId

SPContext.Current.ListItem.ContentTypeId
.

всегда возвращаются

0x00c2208b8ce6e1422CADC1C52142A68B

(который неверный тип идентификатора контента)

Есть свойство loadcontenttenttepes в классе SPContext, но настроить его true для SPContext.Current или FieldIterator.ItemContext не имеет значения.

Что я делаю не так?

Это было полезно?

Решение

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.

Другие советы

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"])
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top