上次修改时间: 2010年5月13日
适用范围: SharePoint Server 2010
本文内容
说明
先决条件
使用此示例
说明
下面的代码示例演示如何使用服务器上的 BDC 管理对象模型,以编程方式将本地化名称添加到元数据对象(此示例中的模型)。
备注
可以使用 BDC 管理客户端对象模型以类似方式在客户端上创建外部内容类型。
先决条件
Microsoft SharePoint Server 2010 或 Microsoft SharePoint Foundation 2010 位于服务器上。
Microsoft .NET Framework 3.5 和 Microsoft Visual Studio 位于客户端计算机上。
使用此示例
启动 Visual Studio 并创建一个 C# 控制台应用程序项目。在创建此项目时,请选择".NET Framework 3.5"。
从"视图"菜单中,单击"属性页"以显示项目属性。
在"生成"选项卡中,为"目标平台"选择"任何 CPU"。
关闭项目属性窗口。
在"解决方案资源管理器"中的"引用"下,删除 System 和 System.Core 之外的所有项目引用。
将以下引用添加到项目中:
Microsoft.BusinessData
Microsoft.SharePoint
System.Web
将 Program.cs 中自动生成的代码替换为此过程结束时列出的代码。
将"<siteUrl>"字符串值替换为有效的 SharePoint 网站名称。
将"<EntityNamespace>"和"<EntityName>"字符串值替换为现有实体的命名空间和实体名称。
保存项目。
编译并运行项目。
备注
有关区域设置和区域设置 ID 的列表,请参阅由 Microsoft 分配的区域设置 ID(该链接可能指向英文页面)。
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);
}
}
}