質問

SharePoint 2007を使ってドキュメントライブラリの項目更新イベントのフィールドの設定に問題があります。

私は次のような状況を持っています、私はドキュメントライブラリを持っています、そして1つのLookupfieldに基づいてドキュメントを追加するとき、私はピッカーを持つ別のルックアップフィールドに値を追加したいですが、失敗します。

しかし、私がドキュメントライブラリとプロパティ編集にすでに文書を持っている場合、アイテムを変更して更新してから、フィールドを更新します。

これに矛盾があると思います。つまり、私が更新したときに私はこの種のデータに渡します:58; #somevalue;#59;#59;#60;#60;#60;#60;#60;#60;#60;

しかし私がテンプレートに文書を追加すると、Lookupフィールドに記入しています。#;#; 59;#;#60;#60;#60;#60;#60;#60;#60;#60;

だから、IDのIDを渡すことを意味しますが、値は空ですが、それを機能させるには、値を持つ必要があるようです。

I Hは次のコードを表します:

public override void ItemUpdating(SPItemEventProperties properties)
        {
            base.DisableEventFiring();
            base.ItemUpdating(properties);

            string nameLookUp = "LookUpField";
            string namePickUp = "LookUpFieldWithPicker";


            string opp = properties.BeforeProperties[namePickUp]==null ? string.Empty : properties.BeforeProperties[namePickUp].ToString();
            string npp = properties.AfterProperties[namePickUp] == null ? string.Empty : properties.AfterProperties[namePickUp].ToString();

            string op = properties.BeforeProperties[nameLookUp] == null ? string.Empty : properties.BeforeProperties[nameLookUp].ToString();
            string np = properties.AfterProperties[nameLookUp] == null ? string.Empty : properties.AfterProperties[nameLookUp].ToString();

            if (!string.IsNullOrEmpty(npp) && opp != npp)
            {
                SPFieldLookupValueCollection value = new SPFieldLookupValueCollection(properties.AfterProperties[namePickUp].ToString());
                properties.AfterProperties[nameLookUp] = properties.AfterProperties[namePickUp];
            }
            else if (!string.IsNullOrEmpty(np) && op != np)
            {
                 properties.AfterProperties[namePickUp] = properties.AfterProperties[nameLookUp];
            }

            base.EnableEventFiring();
        }
.

誰かが私に何かを助言することを願っています...ありがとう

役に立ちましたか?

解決

Take reference to lookup list and use List.GetItemById(Id) to get the item and take the column value and construct the lookup collection. Example: SPList lookupList=properties.web.lists["lookupListName"]; SPListItem lookuplistitem=lookupList.GetItemById(4); //Here Id is 4 string filedvalue=lookuplistitem["lookupfieldname"];//Which field you are taking as lookup now construct the fieldlookup and do the same for all id's and construct fieldlookupvaluecollection.

List.GetItemById(Id) query is faster so you will not get much performance issues.

他のヒント

As per my understanding there are two lookups from same list/library. SPFieldLookupValueCollection for each field is different. The format is ID;#Value here ID is listitem ID and Value is what you stored for respective fields in lookup list.

For "LookUpField" "ID;#LookUpFieldValue"

For "LookUpFieldWithPicker" "ID;#LookUpFieldWithPickerValue"

Before updating the listitem you have to construct the lookup collection like this

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top