Pregunta

Tengo un problema con configurar el campo en el evento de actualización de elementos en la biblioteca de documentos con SharePoint 2007.

Tengo la siguiente situación, tengo una biblioteca de documentos, y cuando agrego un documento basado en un mirador, quiero agregar valores a otro campo de búsqueda con selector, pero falla.

Pero si tengo un documento ya en la biblioteca de documentos y en las propiedades Editar. Modifico el artículo y lo actualizo, entonces actualiza el campo.

He notado cierta inconsistencia en esto, a saber, cuando actualizo, paso a un campo, este tipo de datos: 58; #somevalue; # 59; # safvalue2; # 60; # safvalue3 ...

Pero cuando agrego un documento en la plantilla, complete el campo de búsqueda, obtengo las siguientes cosas para pasar a otro campo de búsqueda con selector: 58; #; 59; #; # 60; #

Entonces significa que pasa la identificación de ella, pero los valores están vacíos, pero parece que también necesito tener valores para que funcione.

i h AVE el siguiente código:

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

Espero que cualquiera pueda aconsejarme algo ... Gracias

¿Fue útil?

Solución

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
scroll top