コード スニペット: クライアントの外部リストからアイテムを削除する

最終更新日: 2010年9月27日

適用対象: SharePoint Server 2010

この記事の内容
説明
前提条件
この例を使用するには

説明

List クラスの DeleteObject メソッドを使用して、クライアントの外部リストから項目を削除します。次のコード スニペットは、クライアント オブジェクト モデルを使用して外部リストから項目を削除する方法を示しています。

前提条件

  • サーバーにインストールされた Microsoft SharePoint Server 2010 あるいは Microsoft SharePoint Foundation 2010。

  • サーバー上の少なくとも 1 つの外部リスト。

  • クライアント コンピューター上の Microsoft Office Professional Plus 2010 と Microsoft .NET Framework 3.5。

  • Microsoft Visual Studio。

この例を使用するには

  1. クライアント コンピューターで Visual Studio を開始し、C# コンソール アプリケーション プロジェクトを作成します。プロジェクトを作成するときに、[.NET Framework 3.5] を選択します。

  2. [表示] メニューから、[プロパティ ページ] をクリックしてプロジェクト プロパティを表示します。

  3. [ビルド] タブから、[プラットフォーム ターゲット] で、[Any CPU] を選択します。

  4. プロジェクト プロパティ ウィンドウを閉じます。

  5. [ソリューション エクスプローラー] の [参照設定] で、[System] と [System.Core] を除いて、すべてのプロジェクト参照を削除します。

  6. プロジェクトに以下の参照を追加します。

    1. Microsoft.SharePoint.Client

    2. Microsoft.SharePoint.Client.Runtime

    3. System.XML

  7. この手順の最後に示すコードで、Program.cs で自動生成されたコードを置換します。

  8. <TargetSiteUrl>、<TargetListName> および <BdcIdentity> の値を有効な値で置き換えます。有効な BdcIdentity 値を取得する方法については、「コード スニペット: サーバー上の外部リストのすべてのアイテムの BdcIdentity を取得する」を参照してください。

  9. プロジェクトを保存します。

  10. プロジェクトをコンパイルして、実行します。

using System;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Runtime;

namespace Microsoft.SDK.Sharepoint.Samples
{
    class Program
    {
        // Note: Replace these with your actual Site url and List name
        private static string TargetSiteUrl = "<TargetSiteUrl>";
        private static string TargetListName = "<TargetListName>";

        /// <summary>
        /// Example to illustrate using CSOM to retrieve external List data        
        /// </summary>        
        static void Main(string[] args)
        {
            ClientContext clientContext = new ClientContext(TargetSiteUrl);
            List externalList = 
                clientContext.Web.Lists.GetByTitle(TargetListName);
            ListItem specifcItem = externalList.GetItemById(
                "<BdcIdentity>");           
            specifcItem.DeleteObject();
            clientContext.ExecuteQuery();          
        }        
    }
}