Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Problem Copying a SPListItem over to another identical SPList

  Asked By: Stella    Date: Mar 07    Category: Sharepoint    Views: 2129

I have 2 identical Survey lists both created from the same template.
In my event handler I want to copy an item from Survey A to Survey B
when the user fills out the survey and submits it. My event handler
will successfully create a new item in Survey B when Survey A is
submited but I can't seem to copy the actual Survey A item with its
results. Here's my code below...

public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);

SPSite siteCollection = null;
SPWeb web = null;
SPList survey = null;

try
{
siteCollection = new SPSite("MY_SITE");
web = siteCollection.OpenWeb();
survey = web.Lists["Private Survey"];


SPListItem listItem = survey.Items.Add();


//Here's where I try to copy one item to the other
listItem = properties.ListItem;

listItem.Update();

}
catch (Exception e)
{

}
finally
{
web.Dispose();
siteCollection.Dispose();

}

}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Cristopher Gould     Answered On: Mar 07

You need to open the Survey A list item  and get the data and then add  a new
item to Survey B list. It appears that your code  is updating the list properties
of Survey B with the list properties  from Survey A.

 




Tagged: