콘텐츠 형식이있는 목록의 Spfields가 예상대로 업데이트되지 않습니다.

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

  •  09-12-2019
  •  | 
  •  

문제

여기에 누락 된 퍼즐의 큰 조각이 있습니다.

콘텐츠 유형이 활성화 된 목록이 있습니다.FeatureUpgrading 메소드의 일부 선택 필드에 옵션을 추가하려고합니다.필드 컬렉션의 필드가 업데이트되지만 목록의 콘텐츠 형식의 필드는 아닙니다.

아래 코드 :

eventreciever.cs

public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
{
    SPWeb web = (SPWeb)properties.Feature.Parent;

    switch ( upgradeActionName ) {
        case "AddChoice":
            AddChoice(web.Fields[new Guid(parameters["FieldID"])] as SPFieldMultiChoice, parameters["Choice"]);
            break;
    }
}

protected static void AddChoice(SPFieldMultiChoice field, string choice) {
    if ( field == null ) {
        throw new ArgumentNullException("field");
    }

    field.Choices.Add(choice);
    field.Update(true);
}
.

template.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
    <UpgradeActions>
        <VersionRange BeginVersion="0.0.0.0" EndVersion="1.0.1.0">
            <CustomUpgradeAction Name="AddChoice">
                <Parameters>
                    <Parameter Name="FieldID">{82E08EC3-0C5C-4565-B0D1-740BDBE4FA93}</Parameter>
                    <Parameter Name="Choice">METT</Parameter>
                </Parameters>
            </CustomUpgradeAction>
            <CustomUpgradeAction Name="AddChoice">
                <Parameters>
                    <Parameter Name="FieldID">{1C2947AF-86EB-4DD0-95AF-D27FBA8EE3BC}</Parameter>
                    <Parameter Name="Choice">METT</Parameter>
                </Parameters>
            </CustomUpgradeAction>
            <CustomUpgradeAction Name="AddChoice">
                <Parameters>
                    <Parameter Name="FieldID">{EBA64EAA-000E-46EE-B1DE-C9761899A31B}</Parameter>
                    <Parameter Name="Choice">METT</Parameter>
                </Parameters>
            </CustomUpgradeAction>
        </VersionRange>
    </UpgradeActions>
</Feature>
.

시간에 감사드립니다.

업데이트 :

아래의 Derek Gusoff의 코멘트에 따르면 아래의 AddChoice 방법을 아래의 코드로 변경했습니다.그래도 작동이 안되는.나는 당신이 이것을 어떻게 할 수 있는지 여전히 잃어버린다.

protected static void AddChoice(SPWeb web, SPFieldMultiChoice field, string choice) {
    if ( field == null ) {
        throw new ArgumentNullException("field");
    }

    field.Choices.Add(choice);
    field.Update(true);

    SPFieldLink fieldLink = new SPFieldLink(field);

    foreach ( SPList list in web.Lists ) {
        if ( !list.ContentTypesEnabled ) continue;

        bool update = false;

        foreach ( SPContentType contentType in list.ContentTypes ) {
            if ( contentType.FieldLinks[field.Id] == null ) continue;

            update = true;

            string[] order = ( from SPFieldLink f in contentType.FieldLinks select f.Name ).ToArray();

            contentType.FieldLinks.Delete(field.Id);
            contentType.FieldLinks.Add(fieldLink);
            contentType.FieldLinks.Reorder(order);

            contentType.Update(true);
        }

        if ( update ) {
            list.Update(true);
        }
    }
}
.

도움이 되었습니까?

해결책 2

나는 그것을 알아 냈다.기능 업그레이드를 트리거하여 기능을 수동으로 업그레이드해야합니다.그 자체로 솔루션을 업그레이드하는 것은 이렇게하지 않습니다.이렇게하는 가장 좋아하는 방법은 "nofollow"> http://spfeatureupgrade.codeplex.com/"> 입니다.

이 문제를 알아 냈습니다. 내 변경 사항에 대한 변경 사항을 내용 유형의 Call SPContentType.Update(true)에 누르기 위해해야합니다.내 코드는 다음과 같습니다.

eventreciever.cs

public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
{
    SPWeb web = (SPWeb)properties.Feature.Parent;

    switch ( upgradeActionName ) {
        case "PushFieldUpdatesToList":
            PushFieldUpdatesToList(web.Fields[new Guid(parameters["FieldID"])]);
            break;
    }
}

protected static void PushFieldUpdatesToList(SPField field) {
    if ( field == null ) {
        throw new ArgumentNullException("field");
    }

    field.Update(true);
}
.

template.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
    <UpgradeActions>
        <VersionRange BeginVersion="0.0.0.0" EndVersion="1.0.1.0">
            <CustomUpgradeAction Name="PushFieldUpdatesToList">
                <Parameters>
                    <Parameter Name="FieldID">{82E08EC3-0C5C-4565-B0D1-740BDBE4FA93}</Parameter>
                </Parameters>
            </CustomUpgradeAction>
        </VersionRange>
    </UpgradeActions>
</Feature>
.

이것은 다른 누군가를 돕기를 바랍니다.그것은 정확히 가장 직관적 인 과정이 아닙니다.당신의 시간 동안 다시 감사드립니다.

다른 팁

편집 : 마지막으로 메모리가 확인하지 않고 답변을 드리려고했는데 잘못되었습니다.미안합니다.나는 다시 가난하게 생각하는 대답을 다시 시작하지 않을 것입니다.이번에는 두 가지 콘텐츠 형식이있는 목록을 만들었습니다. 둘 다 '지역'이라는 선택 필드가있었습니다.그런 다음 콘솔 응용 프로그램 에서이 코드를 실행했습니다.

 SPList list = web.Lists.TryGetList("blah");
 if (list != null)
 {                   
     SPFieldChoice fld = list.Fields["region"] as SPFieldChoice;
     fld.Choices.Add("southwest");
     fld.Update();
 }
.

이렇게하면 목록의 콘텐츠 유형 모두에서 선택 필드가 업데이트되었습니다.나는 이것이 당신이 지난 후에 당신이되기를 바랍니다.기능 수신기에서 수정없이 실행되어야합니다.

또한 샌드 박스에서는 작동하지 않습니다.코드를 스테핑 할 때 작동하는 것처럼 보이지만 필드는 업데이트되지 않습니다.모든 계정으로 작동해야하지만 그렇지 않습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top