Domanda

Ho un problema con l'impostazione del campo nell'elemento Aggiornamento dell'evento in Biblioteca Documenti con SharePoint 2007.

Ho la seguente situazione, ho una libreria documenti e quando aggiungo un documento in base a un campo di ricerca, voglio aggiungere valori a un altro campo di ricerca con raccogliere, ma fallisce.

Ma se ho un documento già nella libreria documenti e nelle proprietà modifica modificare l'elemento e lo aggiorno, aggiornando il campo.

Ho notato qualche incoerenza in questo, vale a dire quando aggiorno il passaggio a un campo questo tipo di dati: 58; #somevalo; # 59; # Somevalue2; # 60; # Somevalo 3 ...

Ma quando aggiungo un documento nel modello, compilo il campo di ricerca, ottengo le seguenti cose da passare a un altro campo di ricerca con raccogliere: 58; #; 59; #; # 60; #

Quindi significa che passa l'ID, ma i valori sono vuoti, ma sembra che io abbia bisogno di avere valori, per farlo funzionare.

I h ha il seguente codice:

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();
        }
.

Spero che qualcuno possa consigliarmi qualcosa ... grazie

È stato utile?

Soluzione

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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top