コード スニペット: Administration オブジェクト モデルを使用して MetadataObject にローカライズされた名前を追加する

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

適用対象: SharePoint Server 2010

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

説明

次のコード例では、サーバー上で BDC Administration オブジェクト モデルを使用して、ローカライズされた名前をメタデータ オブジェクト (この例ではモデル) にプログラムによって追加する方法を示します。

注意

同様に、クライアントに対して外部コンテンツ タイプを作成するには、BDC Administration クライアント オブジェクト モデルを使用することができます。

前提条件

  • サーバー上の Microsoft SharePoint Server 2010 あるいは Microsoft SharePoint Foundation 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.BusinessData

    2. Microsoft.SharePoint

    3. System.Web

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

  8. 有効な SharePoint サイトの名前で、"<siteUrl>" 文字列値を置換します。

  9. 既存のエンティティの名前空間とエンティティ名で、"<EntityNamespace>" 文字列値と "<EntityName>" 文字列値を置換します。

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

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

    注意

    ロケールとロケール ID のリストについては、「Locale IDs Assigned by Microsoft (英語)」を参照してください。

using System;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.SharePoint.BusinessData.Administration;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Microsoft.SDK.SharePoint.Samples.Bdc.AddLocalizedName
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the Catalog for the SharePoint site.
            BdcService service =
                SPFarm.Local.Services.GetValue<BdcService>(String.Empty);
            SPSite site = new SPSite("<siteUrl>");
            SPServiceContext context = SPServiceContext.GetContext(site);
            AdministrationMetadataCatalog catalog =
                service.GetAdministrationMetadataCatalog(context);

            // Retrieve an existing entity.
            Entity entity = 
                catalog.GetEntity("<entityNamespace>", "<entityName>");

            // Add a localized name to entity.
            Console.WriteLine("Localized name to add: ");
            string entityLozalizedName = Console.ReadLine();
            Console.WriteLine("Adding localized name to entity: "
                + entity.Name);

            // Add localized name for the current culture.
            entity.LocalizedDisplayName = entityLozalizedName;

            // Add localized name to specific culture.
            entity.LocalizedDisplayNames.Add(5555, entityLozalizedName);

            entity.Update();
            if (entity.ContainsLocalizedDisplayName())
                Console.WriteLine("Entity " + entity.Name +
                    " was updated with localized name " +
                    entity.LocalizedDisplayName);

        }
    }
}

関連項目

参照

BdcService

Services

AdministrationMetadataCatalog

GetAdministrationMetadataCatalog(SPServiceContext)

Entity

GetEntity(String, String)

LocalizedDisplayName

LocalizedDisplayNames

Update()

ContainsLocalizedDisplayName()