How to delete a large number of data in SharePoint for List when refreshing data?
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?的更多相关文章
- 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 ...
- 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 ...
- Core Data系列文章(一)Core Data基础
在iOS开发数据库SQLite的使用介绍了iOS中使用SQLite对数据进行持久化存储,实际上是对数据库直接进行操作,而苹果专门有一套API来间接的对数据进行持久化存储,而且主要针对用户创建的对象 - ...
- 谈谈WCF中的Data Contract(3):WCF Data Contract对Collection & Dictionary的支持
谈谈WCF中的Data Contract(3):WCF Data Contract对Collection & Dictionary的支持 在本篇文章上一部分Order Processing的例 ...
- 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 ...
- 什么是data:image/png;base64,?一道关于Data URI Scheme的入门级CTF_Web题
一道关于Data URI Scheme的入门级CTF_Web题 0x00 题目描述 这是偶尔遇到的某网安交流群的入群题,题目没有任何的提示,直接给了一个txt文件. 0x01 解题过程 通过给的这个文 ...
- 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 ...
- inserting a large number of records with SQLiteStatement.
Below is a demo application I wrote that creates 100 records programmatically, inserts them using on ...
- 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 ...
随机推荐
- STM32之SD卡
目录 一.SD卡概述 1.定义 2.容量等级 3.SD卡框图 4.SD卡与TF卡的区别 二. SD卡内部结构 1. SD卡内部结构简图 2. 存储阵列结构图 3.Buffer 4.“存储阵列Block ...
- 集合工具类 - CollectionUtil.java
集合工具类,提供数组转LIST.数组转SET.合并集合.计算笛卡儿积等方法. 源码如下:(点击下载 - CollectionUtil.java.ArrayUtil.java.commons-lang ...
- 重燃你的PHP安全分析之火
关于脚本安全这个话题好像永远没完没了,如果你经常到国外的各种各样的bugtraq上,你会发现有一半以上都和脚本相关,诸如SQL injection,XSS,Path Disclosure,Remote ...
- 完美卸载SQL Server 2008的方案
转自完美卸载SQL Server 2008的方案 针对SQL数据库卸载不完全的现象,做了如下总结: 1,控制面板 卸载 首先,打开控制面板,按照"安装时间"进行排序,卸载S ...
- 常用mysql命令(经常更新)
insert into hr_t_clubschedule(clubid) select clubid from hr_t_clubschedule where id=45;//获取指定数据,并插入数 ...
- C++解析JSON之JsonCPP
一.JSON简介 JSON全称为JavaScript ObjectNotation,它是一种轻量级的数据交换格式,易于阅读.编写.解析. JSON由两种基本结构构成: )"名称/值" ...
- android 读写SD卡文件
参考: http://www.oschina.net/code/snippet_176897_7336#11699 写文件: private void SavedToText(Context cont ...
- BZOJ_1208_&_Codevs_1258_[HNOI2004]_宠物收养所_(平衡树/set)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1208 (据说codevs要更新?就不放codevs的地址了吧...) 有宠物和人,每个单位都有 ...
- v8 javascript engine
https://code.google.com/p/v8-wiki/wiki/BuildingWithGYP vs2013git v8 http://github.com/v8/v8-git-mirr ...
- Muduo-Base-Exception(未完待续)
Exception类 主要功能: 能够对异常信息进行输出 能够输出调用的关系 方便我们对某些信息进行调试 系统调用:#include <execinfo.h>int backtrace(v ...