양식 컨트롤에서 항목 콘텐츠 유형을 확인하는 방법 (예를 들어 필드 반복자)?

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

문제

렌더링 된 필드 컨트롤 방식을 변경하려면 내 ListFieldIterator를 구현했습니다. 항목 콘텐츠 유형에 따라 양식의 동작을 변경하고 싶습니다. 그러나 코드에서 ContentTypeID를 결정하려는 시도는 잘못된 결과를 반환합니다.

ListFieldIterator.ListItem.ContentTypeId

SPContext.Current.ListItem.ContentTypeId
.

는 항상 반환됩니다

0x00C2208B8CE6E1422CADC1C521EAB2A68B

(유효하지 않은 내용 유형 ID)

spcontext 클래스에 속성 loadContentTypes가 있지만 SPContext.Current 또는 FieldIterator.ItemContext에서 true를 설정하면 차이가 없습니다.

무엇을 잘못하고 있습니까?

도움이 되었습니까?

해결책

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