none
Copying SharePoint Survey list Responses from one survey list to another servey list using event receivers RRS feed

  • Question

  • Hi All,

    I would like to copy the survey list responses from one survey list to other survey list using event receiver. Please help me by assisting or providing any referrals.

    Your help should be appreciated.

    Thanks,

    Nag544. 


    • Edited by Nag44 Wednesday, April 5, 2017 4:00 AM
    Wednesday, April 5, 2017 12:59 AM

All replies

  • Hi,

    Try with below solution:

    Save the source survey list as template(no content) and create the ‘backup’ survey list based on template.

    Then add below code in event receiver for source survey list.

     

    public override void ItemAdded(SPItemEventProperties properties)
            {
                base.ItemAdding(properties);
                try
                {
                    SPWeb web = properties.List.ParentWeb;
                    SPList sourceSurvey = properties.List;
                    //source survey list
                    if (sourceSurvey.Title == "Survey")
                    {
                        // target survey list
                        SPList targetSurvey = web.Lists.TryGetList("Survey2");
                        SPListItem item = properties.ListItem;
                        var _item = targetSurvey.Items.Add();
                        foreach (SPField field in item.Fields)
                        {
                            if (!field.ReadOnlyField)
                            {
                                _item[field.StaticName] = item[field.StaticName];
                            }
                        }
                        _item.Update();
                    }
    
                }
                catch (Exception ex)
                {
                    //process exception here
                }
            }

    Best Regards,

    Lee


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

    Thursday, April 6, 2017 5:05 AM
  • Hi,

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

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

    You can also share your own solution here and mark it as answer, and we can learn from each other.

    Best Regards,

    Lee


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

    Monday, April 17, 2017 12:31 PM