I have my source list data in the sourceList
data table and want to copy that data to its root list.
How can I do that?
private void MoveToTopTaskList(DataTable sourceList, SPSite DestinationSiteCollection)
{
SPWeb Destinationsite = DestinationSiteCollection.OpenWeb();
SPList DestinationList = Destinationsite.Lists[TASKS];
SPListItem DestinationListItem = DestinationList.Items.Add();
foreach (DataRow row in sourceList.Rows)
{
}
}
Best Approach for the above case is to Use the ProcessBatchData Method of the SPWeb Object. This will help you to update List items in to the List in Batch.
In case if you want to do it using the OM. Then follow code
`SPWeb Destinationsite = DestinationSiteCollection.OpenWeb();
SPList DestinationList = Destinationsite.Lists[TASKS];
SPListItem DestinationListItem = DestinationList.Items.Add();
foreach (DataRow row in sourceList.Rows)
{
DestinationListItem = DestinationList.Items.Add();
DestinationListItem["Field1"]=row["Col"].ToString();
DestinationListItem["Fieldn"]=row["Coln"].ToString();
DestinationListItem.Update()
}
`