Skip to main content
added 48 characters in body
Source Link
Jussi Palo
  • 8.2k
  • 1
  • 20
  • 36

You can modify item properties, except ID like this.

public override void ItemAdding(SPItemEventProperties properties)
{
    string mycol_internal = "";

    using (SPWeb web = properties.OpenWeb()) {
        mycol_internal = web.Lists[properties.ListId].Fields["My Column"].InternalName;
    }

    properties.AfterProperties[mycol_internal] = "your new value";

    //Update title with another column value etc
    properties.AfterProperties["Title"] = properties.AfterProperties[mycol_internal].ToString();
}

Source

OR, use ItemAdded where properties.ListItem is available.

You can modify item properties, except ID like this.

public override void ItemAdding(SPItemEventProperties properties)
{
    string mycol_internal = "";

    using (SPWeb web = properties.OpenWeb()) {
        mycol_internal = web.Lists[properties.ListId].Fields["My Column"].InternalName;
    }

    properties.AfterProperties[mycol_internal] = "your new value";

    //Update title with another column value etc
    properties.AfterProperties["Title"] = properties.AfterProperties[mycol_internal].ToString();
}

Source

You can modify item properties, except ID like this.

public override void ItemAdding(SPItemEventProperties properties)
{
    string mycol_internal = "";

    using (SPWeb web = properties.OpenWeb()) {
        mycol_internal = web.Lists[properties.ListId].Fields["My Column"].InternalName;
    }

    properties.AfterProperties[mycol_internal] = "your new value";

    //Update title with another column value etc
    properties.AfterProperties["Title"] = properties.AfterProperties[mycol_internal].ToString();
}

Source

OR, use ItemAdded where properties.ListItem is available.

Source Link
Jussi Palo
  • 8.2k
  • 1
  • 20
  • 36

You can modify item properties, except ID like this.

public override void ItemAdding(SPItemEventProperties properties)
{
    string mycol_internal = "";

    using (SPWeb web = properties.OpenWeb()) {
        mycol_internal = web.Lists[properties.ListId].Fields["My Column"].InternalName;
    }

    properties.AfterProperties[mycol_internal] = "your new value";

    //Update title with another column value etc
    properties.AfterProperties["Title"] = properties.AfterProperties[mycol_internal].ToString();
}

Source