zoukankan      html  css  js  c++  java
  • 在Sharepoint中批量删除大量条目

    在Sharepoint开发中可能需要一次删除成百上千条记录,这时候如果轮询SPList.Items并直接调用该对象的删除方法来删除的话性能极差,会叫你崩溃。

    下面介绍一个快速删除大量数据的方法:

    using (SPWeb myweb = mysite.AllWebs[“XXXX”])
    {
    SPListItemCollection itemsCollection=CurrentList.Items;
    
    StringBuilder sbDelete = new StringBuilder(); 
    sbDelete.Append("<?xml version="1.0" encoding="UTF-8"?><Batch>"); 
    foreach (SPListItem item in itemsCollection) 
    { 
        sbDelete.Append("<Method>"); 
        sbDelete.Append("<SetList Scope="Request">" + CurrentList.ID + "</SetList>"); 
        sbDelete.Append("<SetVar Name="ID">" + Convert.ToString(item.ID) + "</SetVar>"); 
        sbDelete.Append("<SetVar Name="Cmd">Delete</SetVar>"); 
        sbDelete.Append("</Method>"); 
    } 
    sbDelete.Append("</Batch>");
    
    try 
    { 
        myweb.ProcessBatchData(sbDelete.ToString()); 
    } 
    catch (Exception ex) 
    { 
    Console.WriteLine("Delete failed: " + ex.Message); 
    throw; 
    }
    }
    

      

  • 相关阅读:
    常见的几种性能测试指标及计算公式
    性能测试分析
    性能测试的流程
    性能测试的基本知识
    Python的深拷贝、浅拷贝
    Http基础知识
    求List<int>中相等且连续的偶数的索引
    unity资源打包之后配置的生成
    unity在资源打包的时候,关于 hash 计算的简单总结
    C#中string.Join的用法
  • 原文地址:https://www.cnblogs.com/ricky_li/p/4934579.html
Copyright © 2011-2022 走看看