zoukankan      html  css  js  c++  java
  • SharePoint中删除列表记录

    方法1(快速,以理解,可以封装):

    SPList spListQuestion = spWeb.Lists["Question List"];
    for (int i = spListQuestion.Items.Count - 1; i >= 0; i--)
    {
        spListQuestion.Items[i].Delete();
    }

    方法2(繁琐):

    SPList spListQuestion = spWeb.Lists["Question List"];
    string sDIDTitle = spListQuestion.Fields["DID"].InternalName;
    SPQuery spQuery = new SPQuery();
    spQuery.Query = "" + "" + spDocItem.ID.ToString() + "";
    SPListItemCollection collListItems = spListQuestion.GetItems (spQuery);
    for (int i = 0; i < collListItems.Count; i++)
    {
        string ID = collListItems[i]["ID"].ToString();
        SPItem spItem = spListQuestion.GetItemById (Int16.Parse (ID) );
        spItem.Delete();
    }

    方法3(推荐):

    SPList targetList = null;
    try
    {
        targetList = currentWeb.GetList (currentWeb.ServerRelativeUrl.TrimEnd ('/') + listUrl);
    }
    catch { }
    if (targetList != null)
    {
        StringBuilder sbDelete = new StringBuilder();
        sbDelete.Append ("<?xml version="1.0" encoding="UTF-8"?><Batch>");
        foreach (SPItem item in targetList.Items)
        {
            if (item["Title"] != null)
            {
                sbDelete.Append ("<Method>");
                sbDelete.Append ("<SetList Scope="Request">" + targetList.ID + "</SetList>");
                sbDelete.Append ("<SetVar Name="ID">" + Convert.ToString (item.ID) + "</SetVar>");
                sbDelete.Append ("<SetVar Name="Cmd">Delete</SetVar>");
                sbDelete.Append ("</Method>");
            }
        }
        sbDelete.Append ("</Batch>");
        try
        {
            currentWeb.ProcessBatchData (sbDelete.ToString() );
            targetList.Update();
        }
        catch (Exception ex)
        { }
    }
  • 相关阅读:
    linux常用命令整理
    pg_sql常用查询语句整理
    python 爬取媒体文件(使用chrome代理,启动客户端,有防火墙)
    python 爬取媒体文件(无防火墙)
    python读写符号的含义
    python数据分析开发中的常用整理
    wget: 无法解析主机地址
    ## nginx 使用
    iptables防火墙
    【redis】Could not connect to Redis at 127.0.0.1:6379: Connection refused
  • 原文地址:https://www.cnblogs.com/yixiaozi/p/3702614.html
Copyright © 2011-2022 走看看