0

I am trying to update list field using ItemAdding,

public override void ItemAdding(SPItemEventProperties properties)
    {


        SPListItem curListItem = properties.ListItem;
        curListItem.Web.AllowUnsafeUpdates = true; // This property should be set to true for the update to go through
        curListItem["Age"] = "";
        curListItem.Update(); // This line should update the ListItem but it doesnt

    }

UPDATE

  public override void ItemAdding(SPItemEventProperties properties)
    {

        string empty = "";
        properties.AfterProperties["Age"] = empty;
        base.ItemAdding(properties);

    }
2
  • 1
    You are using ItemAdding not ItemUpdated in the code. Commented Jun 16, 2015 at 11:22
  • I wrote wrong i mean ItemAdding will update Commented Jun 16, 2015 at 11:29

1 Answer 1

1

Use properties.AfterProperties["Age"] = "Your Value";

See Set custom field value in ItemAdding event for more information.

7
  • I have a custom list in a teamsite, what should i have in elements.xml for the list ? i have right not ListUListUrl="sites/test/Drafts" on that url is my list? Commented Jun 16, 2015 at 11:39
  • <Receivers ListTemplateId="100"> Commented Jun 16, 2015 at 11:43
  • i will update, my code thas not clear item added column Commented Jun 16, 2015 at 11:50
  • Try setting a debug point. Make sure your code is getting executed. Commented Jun 16, 2015 at 11:56
  • yes it enters my itemadding but the field does not get empty Commented Jun 16, 2015 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.