Preface

Recently thequestion was asked in the newsgroups about deleting a large number of itemsfrom SharePoint (WSS) in the fastest way. I had, in one if my projects,needed to remove a large number of items from SharePoint
and the best way Ifound were to use 'ProcessBatchData' as it avoided the API and was considerablyfaster.

1.     Delete Common List

1.1 CAML format

<?xml version="1.0"encoding="UTF-8"?

>

<Batch>

<Method>

  <SetListScope="Request">3010913d-9373-44ec-a799-0bf564cb0d66</SetList>

  <SetVar Name="Cmd">DELETE</SetVar>

  <SetVar Name="ID">1</SetVar>

</Method>

</Batch>

1.2  C# source code implementation

StringBuilder sbDelete = new StringBuilder();

sbDelete.Append("<?xml version=\"1.0\"encoding=\"UTF-8\"?><Batch>");



foreach (SPListItem item in CurrentList.Items)

{

    sbDelete.Append("<Method>");

    sbDelete.Append("<SetListScope=\"Request\">" + CurrentList.ID +"</SetList>");

    sbDelete.Append("<SetVarName=\"ID\">" + Convert.ToString(item.ID) +"</SetVar>");

    sbDelete.Append("<SetVarName=\"Cmd\">Delete</SetVar>");

    sbDelete.Append("</Method>");

}



sbDelete.Append("</Batch>");

try

{

    SPContext.Current.Site.RootWeb.ProcessBatchData(sbDelete.ToString());

}

catch (Exception ex)

{

    Console.WriteLine("Delete failed: " +ex.Message);

    throw;

}

2.      Delete Documentlibrary list

2.1 CAML (Collaborative Application Markup Languageformat

<?xml version="1.0"encoding="UTF-8"?>

<Batch>

<Method ID='1' Cmd='Delete'>

  <Field Name='ID'>1</Field>

  <Field Name='FileRef'>http://basesmcdev/sites/tester1/myfile.bmp</Field>

</Method>

</Batch>

2.2 C# source code implementation

SPSecurity.RunWithElevatedPrivileges(delegate()

            {

                using (SPSite site = new SPSite("http://virus/sites/intranet"))

                {



                    using (SPWeb web = site.OpenWeb("team"))

                    {

                        site.AllowUnsafeUpdates = true;

                        web.AllowUnsafeUpdates = true;



                        SPList list = web.Lists["documentExample"];

                        StringBuilder sbDelete = new StringBuilder();

                        sbDelete.Append(\"?><Batch>");



                        foreach (SPListItem item in list.Items)

                        {

                            sbDelete.Append("<Method>");

                            sbDelete.Append("<SetList Scope=\"Request\">" + list.ID + "</SetList>");

                            sbDelete.Append("<SetVar Name=\"ID\">" + Convert.ToString(item.ID) + "</SetVar>");

                            sbDelete.Append("<SetVar Name=\"Cmd\">Delete</SetVar>");

                            sbDelete.Append("<SetVar Name=\"owsfileref\">"+item.GetFormattedValue("FileRef")+"</SetVar>");

                            sbDelete.Append("</Method>");

                        }



                        sbDelete.Append("</Batch>");



                        try

                        {

                            Console.WriteLine( web.ProcessBatchData(sbDelete.ToString()));

                        }

                        catch

                        {



                            throw;

                        }

                        site.AllowUnsafeUpdates = false;

                        web.AllowUnsafeUpdates = false;

                    }

                }

            });

Reference documentation

1.    http://www.cnblogs.com/laputa-sky/archive/2008/10/21/1299867.html

2.    http://www.cnblogs.com/virusswb/archive/2009/01/21/1379275.html

3.    http://msdn.microsoft.com/zh-cn/library/ms414322(v=office.14).aspx

4.    http://msdn.microsoft.com/zh-cn/library/ms426449(v=office.14).aspx

5.    Delete Folder http://platinumdogs.me/2009/07/13/delete-a-folder-from-a-sharepoint-document-library/

How to delete a large number of data in SharePoint for List when refreshing data?的更多相关文章

  1. Searching External Data in SharePoint 2010 Using Business Connectivity Services

    from:http://blogs.msdn.com/b/ericwhite/archive/2010/04/28/searching-external-data-in-sharepoint-2010 ...

  2. Error message when you try to modify or to delete an alternate access mapping in Windows SharePoint Services 3.0: "An update conflict has occurred, and you must re-try this action"

    Article ID: 939308 - View products that this article applies to. Expand all | Collapse all Symptoms ...

  3. Core Data系列文章(一)Core Data基础

    在iOS开发数据库SQLite的使用介绍了iOS中使用SQLite对数据进行持久化存储,实际上是对数据库直接进行操作,而苹果专门有一套API来间接的对数据进行持久化存储,而且主要针对用户创建的对象 - ...

  4. 谈谈WCF中的Data Contract(3):WCF Data Contract对Collection & Dictionary的支持

    谈谈WCF中的Data Contract(3):WCF Data Contract对Collection & Dictionary的支持 在本篇文章上一部分Order Processing的例 ...

  5. jmeter "you cannot switch bacause data cannot be converted to target Tab data,empty data to switch"报错

    jmeter "you cannot switch bacause data cannot be converted to target Tab data,empty data to swi ...

  6. 什么是data:image/png;base64,?一道关于Data URI Scheme的入门级CTF_Web题

    一道关于Data URI Scheme的入门级CTF_Web题 0x00 题目描述 这是偶尔遇到的某网安交流群的入群题,题目没有任何的提示,直接给了一个txt文件. 0x01 解题过程 通过给的这个文 ...

  7. shell delete with line number

    If you want to delete lines 5 through 10 and 12: sed -e '5,10d;12d' file This will print the results ...

  8. inserting a large number of records with SQLiteStatement.

    Below is a demo application I wrote that creates 100 records programmatically, inserts them using on ...

  9. csharp: ODP.NET,System.Data.OracleClient(.net 4.0) and System.Data.OleDb读取Oracle g 11.2.0的区别

    ODP.NET: 引用: using Oracle.DataAccess; //Oracle g 11.2.0 using Oracle.DataAccess.Client; using Oracle ...

随机推荐

  1. 在后台代码中引入XAML的方法

    本文将介绍三种方法用于在后台代码中动态加载XAML,其中有两种方法是加载已存在的XAML文件,一种方法是将包含XAML代码的字符串转换为WPF的对象. 一.在资源字典中载入项目内嵌资源中的XAML文件 ...

  2. 动画讲解 Eclipse 常用快捷键

    Eclipse有强大的编辑功能, 工欲善其事,必先利其器, 掌握Eclipse快捷键,可以大大提高工作效率. 小坦克我花了一整天时间, 精选了一些常用的快捷键操作,并且精心录制了动画, 让你一看就会. ...

  3. UISearchBar -- 备忘

    搜索功能的备忘 UISearchBar UISearchBar是一个搜索栏,继承自UIView,也是常用的控件之一,所以特别写一篇备忘方便以后做工具文章. 例子: let searchBar = UI ...

  4. android SurfaceView绘制 重新学习--切图clipRect详解

    解释都在代码注释中: public class SampleView extends View { private Paint mPaint; private Path mPath; public S ...

  5. 今天把登陆注册给改成tab了

    真是解决了一个心头大患,本来以为必须请外包公司的工程师才做,自己研究了下也给解决了. 多亏去年做原型时学习了smarty.css.html这些最基本的网站前端开发的技术.FTP上传下载.linux的基 ...

  6. 李洪强漫谈iOS开发[C语言-028]-sizeof运算符

  7. 利用TEA算法进行数据加密

    TEA(Tiny Encryption Algorithm)是一种小型的对称加密解密算法,最初是由剑桥计算机实验室的 David Wheeler 和 Roger Needham 在 1994 年设计. ...

  8. 【CF】3B Lorry

    这道题目网上有几个题解,均有问题.其实就是简单的贪心+排序,没必要做的那么复杂.一旦tot+curv > v时,显然curv==2, 有三种可能:(1)取出最小的curv==1的pp,装入当前的 ...

  9. 【HDOJ】1969 Pie

    二分. #include <stdio.h> #include <math.h> ; ]; int main() { int case_n, n, f, m; double r ...

  10. bzoj2209 2329

    括号序列的经典做法把(看成1,)看成-1匹配的括号序列即任意前缀和都非负我们先解决静态的问题,给定一段括号序列求最少修改次数我们先找出最大后缀和a和最小前缀和b之间一定可以不相交显然a+|b|个括号是 ...