none
How to create a new item in a list while updating a item?

    Question

  • HOw to create a item when updating a item. In details, if item updated new item should create instead update that item. HOw to achieve this, thanks in advance
    Friday, December 02, 2016 11:02 AM

All replies

  • Hi SamDany,

    You can use itemupdating event receiver create new item and on that segment use properties.cancel=true after item.update.

    https://www.captechconsulting.com/blogs/update-a-sharepoint-list-item-in-an-itemupdated-event-without-an-endless-loop

    Code:-

                

    public override void ItemUpdating(SPItemEventProperties properties)
    {
        InsertEnquiryToSharepoint();//this will add new item to list change the parameters for input and column name too.
    properties.cancel=true;//add it u don't want to update list
    }
    protected void InsertEnquiryToSharepoint()
    {
        string strDashListRoot = "http://spSite/SubSite/Lists/MyList/";
        using(SPSite site = new SPSite(strDashListRoot))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists["MyList"];
                SPListItem Item = list.Items.Add();
                item["Title"] = txtCompanyName.Text;
                item["DateReceived"] = System.DateTime.Now;
                item["Description"] = txtDescription.Text;
                item.Update();

            }
        }
    }

    Mark as answer if it helps!!


    Thanks Shekhar.diary

    Friday, December 02, 2016 11:16 AM
  • Hi Sam,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    Tuesday, December 20, 2016 1:52 PM
    Moderator