コード スニペット: サーバーあるいはクライアントの FileBackedMetadataCatalog を取得する

最終更新日: 2010年5月5日

適用対象: SharePoint Server 2010

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

説明

次のコード例では、サーバーで Business Data Connectivity (BDC) service ランタイム オブジェクト モデルを使用してサーバーで FileBackedMetadataCatalog を取得する方法を示します。FileBackedMetadataCatalog はクライアントでも使用できます。

前提条件

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

  • クライアント コンピューター上の Microsoft .NET Framework 3.5 と Microsoft Visual Studio。

  • BDC メタデータ ストアに登録された、少なくとも 1 つの外部コンテンツ タイプ。

この例を使用するには

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

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

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

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

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

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

    1. Microsoft.BusinessData (SharePoint_RootFolder\ISAPI から)

    2. Microsoft.SharePoint

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

  8. entityFilePath を有効な値で置換します。

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

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

using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.Runtime;
using Microsoft.SharePoint.BusinessData.MetadataModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.BusinessData.SharedService;
using BDCParser = Microsoft.SharePoint.BusinessData.Parser;

// If using on the client, use these instead of the server DLLs.
//using BDCParser = Microsoft.Office.BusinessData.Parser;
//using Microsoft.Office.BusinessData.MetadataModel;

//entityFilePath is the path where the BDC model is stored on a local computer.
XmlReader reader = XmlReader.Create(entityFilePath); 
BDCParser.ParseContext parseContext = new BDCParser.ParseContext();
FileBackedMetadataCatalog catalog = new FileBackedMetadataCatalog();
catalog.ImportPackage(
                reader,
                parseContext,
                BDCParser.PackageContents.Model
                     | BDCParser.PackageContents.Properties
                     | BDCParser.PackageContents.LocalizedNames
                     | BDCParser.PackageContents.Permissions);          

if (parseContext.Errors.Length > 0)
{
   //Print errors.
}

関連項目

参照

ParseContext

Microsoft.SharePoint.BusinessData.Parser.ParseContext

FileBackedMetadataCatalog

FileBackedMetadataCatalogImportPackage(XmlReader, ParseContext, PackageContents)

Microsoft.SharePoint.BusinessData.MetadataModel.FileBackedMetadataCatalog

FileBackedMetadataCatalog.ImportPackage(XmlReader, ParseContext, PackageContents)