[英]How to copy a DataTable to a SharePoint SPList?
I have my source list data in the sourceList
data table and want to copy that data to its root list. 我在我的源列表数据sourceList
数据表,并希望将数据复制到它的根目录。
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. 上述情况的最佳方法是使用SPWeb对象的ProcessBatchData方法。 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. 如果你想使用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()
}
` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.