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. Remark of BLENDFUNCTION from MSDN

    Remarks When the AlphaFormat member is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, ...

  2. C语言学习笔记——堆和栈——未整理

    C语言笔记     栈区     栈stack是一种先进后出的内存结构,所有的自动变量,函数的形参都是由编译器自动放出栈中,当一个自动变量超出其作用域时,自动从栈中弹出.出入栈是由C语言编译器自动分配 ...

  3. 如何在Win10中启用和关闭管理员账户?

    和Win7/Win8.1一样,Win10的管理员账户Administrator是默认隐藏和关闭的,因为该账户权限极高,被不法分子利用后存在极大风险.但如果你想在某些特殊情况下使用该账户,就需要手动将其 ...

  4. javax.servlet不存在的问题

    摘自:http://blog.csdn.net/tgeh23/article/details/2216682     最近在学习servlet,看书看的似乎还比较理想就想上机试下,这一试就发现,问题来 ...

  5. aspose.cells根据模板导出excel

    又隔十多天没写博客了,最近都在忙项目的事情,公司人事变动也比较大,手头上就又多了一个项目.最近做用aspose.cells根据模板导出excel报价单的功能,顺便把相关的核心记下来,先上模板和导出的效 ...

  6. Computer Vision Applied to Super Resolution

    Capel, David, and Andrew Zisserman. "Computer vision applied to super resolution." Signal ...

  7. maven安装和环境变量配置

    maven安装和环境变量配置 myeclipse自带maven(Maven4MyEclipse)创建项目:新建Web Projects项目,在新建的页面上打上maven的勾.新建的项目里会多出个pom ...

  8. 【Bzoj 3295】 动态逆序对(树套树|CDQ分治)

    [题意] 每次删除一个数,然后问删除前逆序对数. [分析] 没有AC不开心.. 我的树状数组套字母树,应该是爆空间的,空间复杂度O(nlogn^2)啊..哭.. 然后就没有然后了,别人家的树套树是树状 ...

  9. [topcoder]CorrectMultiplicationTwo

    http://community.topcoder.com/stat?c=problem_statement&pm=11609&rd=14547 http://apps.topcode ...

  10. Altium Designer10 如何导出Gerber文件

    版本:AD10.818 目的:Gerber文件导出备忘 http://blog.sina.com.cn/s/blog_9b9a51990100zyyv.html 目录: Step1:设置原点 Step ...