本文整理汇总了C#中SPList.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# SPList.Delete方法的具体用法?C# SPList.Delete怎么用?C# SPList.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPList
的用法示例。
在下文中一共展示了SPList.Delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteItemsAndList
private static void DeleteItemsAndList(SPList list, SPWeb targetWeb)
{
StringBuilder deleteBatch = new StringBuilder();
deleteBatch.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
string mask = "<Method><SetList Scope=\"Request\">" + list.ID + "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
foreach (SPListItem item in list.Items)
{
deleteBatch.Append(string.Format(mask, item.ID));
}
deleteBatch.Append("</Batch>");
targetWeb.ProcessBatchData(deleteBatch.ToString());
list.Delete();
}
示例2: Delete
/// <summary>
/// Deletes the specified list.
/// </summary>
/// <param name="list">The list.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
internal static void Delete(SPList list, bool force)
{
if (list == null)
throw new SPException("List not found.");
if (!list.AllowDeletion && force)
{
list.AllowDeletion = true;
list.Update();
}
else if (!list.AllowDeletion)
throw new SPException("List cannot be deleted. Try using the '-force' parameter to force the delete.");
try
{
list.Delete();
}
catch (Exception)
{
if (force)
{
using (SPSite site = new SPSite(list.ParentWeb.Site.ID))
{
Utilities.RunStsAdmOperation(
string.Format(" -o forcedeletelist -url \"{0}\"",
site.MakeFullUrl(list.RootFolder.ServerRelativeUrl)), false);
}
}
}
}