How to change a field value during an ItemUpdating event

I am trying to set the value of a field in a ListItem in an event receiver, but its not working

Everything I do during the event

properties.AfterProperties[<field internal name>] = 1;

No errors are thrown, but the field that I set does not change. I also tried

properties.ListItem[<field internal name>] = 1;
properties.ListItem.Update();

You also tried SystemUpdate ();

I know that I have to configure afterproperties properties, but I think I'm missing the obvious step.

thank

+3
source share
6 answers

The ItemUpdating element is used for verification. If you want to set field values, do it instead in ItemUpdated.

+1
source

, , , (. ).

, ItemUpdating, , , , :

base.ItemUpdating(properties);
properties.AfterProperties["InternalName"] = 1;

( , )

, . ?

+9

, DisableEventFiring, , , Update? ItemUpdated , ...

+2

Item Adding,  AfterProperties.ListItem [] =;

+1

ItemUpdating, .

properties.AfterProperties [ "FieldName" ] = "computedvalue";
base.EventFiringEnabled = false; properties.ListItem.SystemUpdate();
base.EventFiringEnabled = true;

0

ItemAdding ItemUpdating, ( DisableEventFiring), " "

Sample code to update the header based on the file name. Works for document library and image library. To work with the title in the lists, you must use ["Name"].

public override void ItemAdding(SPItemEventProperties properties)
{
    base.ItemAdding(properties);
    string currTitle = properties.AfterProperties["vti_title"] as string;
    string url = properties.AfterUrl;
    var name = url.Substring(url.LastIndexOf('/') + 1);
    //NOTE! Name is only copied to Title if title is not set. Will not handle name changes!
    if (string.IsNullOrEmpty(currTitle))
    {
        properties.AfterProperties["vti_title"] = name;
    }
}
0
source

Source: https://habr.com/ru/post/1750589/


All Articles