代码段:枚举客户端缓存中的外部内容类型的项
上次修改时间: 2010年5月7日
适用范围: SharePoint Server 2010
本文内容
说明
必备组件
使用该示例
说明
下面的代码示例演示如何枚举客户端缓存中外部内容类型的项。
必备组件
服务器上安装了 Microsoft SharePoint Server 2010 或 Microsoft SharePoint Foundation 2010。
客户端计算机上安装了 Microsoft Office Professional Plus 2010 和 Microsoft .NET Framework 3.5。
Microsoft Visual Studio。
Business Connectivity Services 客户端缓存中至少有一个订阅。
使用该示例
在客户端计算机上启动 Visual Studio,然后创建 C# Office 应用程序加载项项目。在创建项目时,选择".NET Framework 3.5"。
从"视图"菜单中,单击"属性页"以显示项目属性。
在"生成"选项卡中,为"目标平台"选择"任何 CPU"。
关闭项目属性窗口。
在"解决方案资源管理器"中的"引用"下,移除除 System 和 System.Core 之外的所有项目引用。
将以下引用添加到项目中:
Microsoft.BusinessData
Microsoft.Office.BusinessApplications.Runtime
System.Windows.Forms
用以下语句替换现有 using 语句。
using System; using Microsoft.BusinessData.MetadataModel; using Microsoft.Office.BusinessData.MetadataModel; using Microsoft.BusinessData.Runtime; using System.Windows.Forms;
用此过程末尾列出的代码替换加载项的启动事件中的代码。
使用有效值替换 <entityName>、<namespace>、<IdentityField> 和 <Field1>。
保存该项目。
编译并运行该项目。
这应打开 Office 应用程序并显示此代码中输出的消息。
RemoteSharedFileBackedMetadataCatalog RemoteCatalog = new
RemoteSharedFileBackedMetadataCatalog();
IEntity remoteEntity = RemoteCatalog.GetEntity(
"<namespace>", "<entityName>");
ILobSystemInstance LobSysteminstance =
remoteEntity.GetLobSystem().GetLobSystemInstances()[0].Value;
IMethodInstance method = remoteEntity.GetMethodInstance(
"Read List", MethodInstanceType.Finder);
IEntityInstanceEnumerator ieie = remoteEntity.FindFiltered(
method.GetFilters(), LobSysteminstance);
IView view = remoteEntity.GetFinderView(method.Name);
while (ieie.MoveNext())
{
MessageBox.Show(String.Format(
"Id: {0}, Field1: {1}",
ieie.Current["<IdentityField>"],
ieie.Current["<Field1>"]));
}
请参阅
引用
RemoteSharedFileBackedMetadataCatalog
GetMethodInstance(String, MethodInstanceType)