if (!IsPostBack)
{
DeleteAllItems(SPContext.Current.Site.Url, "Nalco My Contacts");
}
public static void DeleteAllItems(string site, string list)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite spSite = new SPSite(site))
{
spSite.AllowUnsafeUpdates = true;
using (SPWeb spWeb = spSite.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
StringBuilder deletebuilder = BatchCommand(spWeb.Lists[list]);
spWeb.ProcessBatchData(deletebuilder.ToString());
}
}
});
}
public static StringBuilder BatchCommand(SPList spList)
{
StringBuilder deletebuilder = new StringBuilder();
deletebuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
"</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
foreach (SPListItem item in spList.Items)
{
deletebuilder.Append(string.Format(command, item.ID.ToString()));
}
deletebuilder.Append("</Batch>");
return deletebuilder;
}
{
DeleteAllItems(SPContext.Current.Site.Url, "Nalco My Contacts");
}
public static void DeleteAllItems(string site, string list)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite spSite = new SPSite(site))
{
spSite.AllowUnsafeUpdates = true;
using (SPWeb spWeb = spSite.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
StringBuilder deletebuilder = BatchCommand(spWeb.Lists[list]);
spWeb.ProcessBatchData(deletebuilder.ToString());
}
}
});
}
public static StringBuilder BatchCommand(SPList spList)
{
StringBuilder deletebuilder = new StringBuilder();
deletebuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
"</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
foreach (SPListItem item in spList.Items)
{
deletebuilder.Append(string.Format(command, item.ID.ToString()));
}
deletebuilder.Append("</Batch>");
return deletebuilder;
}
What's up colleagues, its wonderful piece of writing on the topic
ReplyDeleteof tutoringand completely explained, keep it up all the time.
Here is my web page: health