如何将数据表复制到 SharePoint SPList?

发布于 2024-07-26 18:12:34 字数 450 浏览 7 评论 0 原文

我的源列表数据位于 sourceList 数据表中,并且希望将该数据复制到其根列表。

我怎样才能做到这一点?

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)
    {

    }
}

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)
    {

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味拾荒者 2024-08-02 18:12:34

上述情况的最佳方法是使用 SPWeb 对象的 ProcessBatchData 方法。 这将帮助您将列表项批量更新到列表中。

  1. 您需要构建一个 XML 标签,其中包含将数据插入列表的详细信息。
  2. 如果您有大量记录要插入到列表中,请考虑将其分成较小的批次。 假设您有 1000 条记录,则将其分为两组,每组 500 条。
  3. 构建 XML 时,请确保使用 StringBuilder 类来附加字符串。
  4. 请参阅这些链接 [Link1][1] [Link2][2] [Link3][3] 了解有关 ProcessBatchData 的更多信息

如果您想使用 OM 来执行此操作, 。 然后按照代码

`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()

}

`
[1]:https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-services/cc404818%28v=office.12%29
[2]:https://web.archive.org/web/20121029142042/http://blog.dynatrace.com:80/2009/01/20/sharepoint-using -批量更新以加速性能/

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.

  1. You need to build an XML tags that will have details for inserting the data to the list.
  2. If you have large number of records to be inserted to the list consider spliting it in to smaller batchs. Say if you have 1000 records do it in two 500 sets.
  3. While building the XML make sure you use StringBuilder class to append the string.
  4. Refer these Links [Link1][1] [Link2][2] [Link3][3] for more information on ProcessBatchData

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()

}

`
[1]:https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-services/cc404818%28v=office.12%29
[2]:http://www.sharepointblogs.com/smc750/archive/2008/04/03/spweb-processbatchdata-a-list-is-a-list-is-a-list.aspx
[3]:https://web.archive.org/web/20121029142042/http://blog.dynatrace.com:80/2009/01/20/sharepoint-using-batch-updates-to-speed-up-performance/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文