Вопрос

У меня есть проблема с настройкой поля в событии обновления элементов в библиотеке документов с помощью SharePoint 2007.

У меня есть следующая ситуация, у меня есть библиотека документов, и когда я добавляю документ на основе одного Lookupfield, я хочу добавлять значения на другое поле поиска с помощью Picker, но он не удается.

Но если у меня есть документ, уже в библиотеке документов и в недвижимости Редактировать, я изменяю элемент, и я его обновляю, то он обновляет поле.

Я заметил некоторую несоответствие в этом, а именно, когда я обновляю, я передаю поле в поле этого типа данных: 58; #somevalue; # 59; # quoteValue2; # 60; # quotevalue3 ...

Но когда я добавляю документ в шаблоне, я заполняю поле поиска, я получаю следующие вещи, чтобы перейти на другое поле поиска с помощью Picker: 58; #; 59; #; # 60; #

Так что это означает, что он проходит от этого, но значения пустые, но мне кажется, что мне нужно иметь ценности, чтобы сделать его работать.

i h is следующий код:

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