我有一个问题,在使用SharePoint 2007中设置文档库中的项目更新事件中的字段。

我有以下情况,我有一个文档库,当我基于一个lookupfield添加文档时,我想向一个带有拾取器的另一个查找字段添加值,但它失败了。

但如果我在文档库中的文档和propertiess编辑中,我修改项目并更新它,那么它确实更新了字段。

我已经注意到了一些不一致,即当我更新我传递到一个字段这种数据:58; #somevalue;#59;#somevalue2;#60;#somevalue3 ...

但是当我在模板中添加一个文档时,我填写查找字段,我得到以下内容将通过选择器传递给另一个查找字段:58;#; 59;#;#60;#;#

所以它意味着它传递它的ID,但值是空的,但似乎我也需要有值,以使其工作。

i h ave以下代码:

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归因
scroll top