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. RSA算法原理及实现

    参考资料: 阮哥的日志:http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html http://www.ruanyifeng ...

  2. C++程序的构成和书写形式

    C++程序的结构和书写格式归纳如下:  (1) 一个C++程序可以由一个程序单位或多个程序单位构成.每一个程序单位作为一个文件.在程序编译时,编译系统分别对各个文件进行编译,因此,一个文件是一个编译单 ...

  3. html页面高度不同浏览器兼容性设置

    页面需要嵌套在跨域的iframe中,而页面高度不固定,需要每个页面把自己的高度获得后,通过js通知iframe调整显示. 而页面在获得自己的高度时,发现总是比预想的大.经过参考别人的博客,发现原来是w ...

  4. python学习之---函数进阶

    一,递归函数: 做程序应该都知道,在一个函数的内部还可以调用其它函数,这叫函数的调用,但是有一种特殊的情况,在一个函数内部对自身函数的调用,我们成这为函数的递归调用. 在此,使用一个家喻户晓的例子来演 ...

  5. uva 12097 - Pie

    简单题,二分就行: #include<cstdio> #include<cmath> #define pi acos(-1.0) #define eps 0.000001 #d ...

  6. 如何取消Linux下,vi中显示的^M符号

    http://www.cnblogs.com/dkblog/archive/2012/02/03/2337187.html dos2unix file_name bash: ./configure: ...

  7. Multi-bit per cell storage

    Memories Scaling      其他的的半导体存储器的制程一般2年为一个升级周期,但是nand flash 存储器的制程升级周期和他们比起来只有1年.这种更快的制程升级导致SLC NAND ...

  8. HTML表单和验证事件

    1.表单验证<form></form> (1).非空验证(去空格) (2).对比验证(跟一个值对比) (3).范围验证(根据一个范围进行判断) (4).固定格式验证:电话号码, ...

  9. delphi中EmbeddedWB网页html相互调用(二)

    我们可以通过控件 EmbeddedWB_D5-D2010_Version_14.69.1 来响应html事件,还可以自定义html响应哪些html元素. 控件下载 点击下载 里面有demos文件夹大家 ...

  10. Android中的常见时区

    方法: private void printTimeZone(){ String[] ids= TimeZone.getAvailableIDs(); for (int i = 0; i < i ...