コード スニペット: クライアントの外部リストからアイテムを削除する
最終更新日: 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。
この例を使用するには
クライアント コンピューターで Visual Studio を開始し、C# コンソール アプリケーション プロジェクトを作成します。プロジェクトを作成するときに、[.NET Framework 3.5] を選択します。
[表示] メニューから、[プロパティ ページ] をクリックしてプロジェクト プロパティを表示します。
[ビルド] タブから、[プラットフォーム ターゲット] で、[Any CPU] を選択します。
プロジェクト プロパティ ウィンドウを閉じます。
[ソリューション エクスプローラー] の [参照設定] で、[System] と [System.Core] を除いて、すべてのプロジェクト参照を削除します。
プロジェクトに以下の参照を追加します。
Microsoft.SharePoint.Client
Microsoft.SharePoint.Client.Runtime
System.XML
この手順の最後に示すコードで、Program.cs で自動生成されたコードを置換します。
<TargetSiteUrl>、<TargetListName> および <BdcIdentity> の値を有効な値で置き換えます。有効な BdcIdentity 値を取得する方法については、「コード スニペット: サーバー上の外部リストのすべてのアイテムの BdcIdentity を取得する」を参照してください。
プロジェクトを保存します。
プロジェクトをコンパイルして、実行します。
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();
}
}
}