代码段:枚举 BCS 缓存订阅的订阅关联
上次修改时间: 2010年5月13日
适用范围: SharePoint Server 2010
本文内容
说明
先决条件
使用此示例
说明
以下示例演示如何在客户端上枚举 Business Connectivity Services 缓存订阅的关联订阅。
先决条件
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# Microsoft Office 应用程序加载项项目。创建项目时选择".NET Framework 3.5"。
从"视图"菜单中,选择"属性页"以显示项目属性。
在"生成"选项卡上,为"目标平台"选择"任何 CPU"。
关闭项目属性窗口。
在"解决方案资源管理器"中的"引用"下,删除除 System 和 System.Core 之外的所有项目引用。
向项目中添加以下引用:
Microsoft.Office.BusinessApplications.Runtime
Microsoft.BusinessData
用下面的语句替换现有的 using 语句:
using System; using Microsoft.BusinessData.Offlining; using Microsoft.Office.BusinessData.Offlining;
使用此过程结尾处列出的代码替换加载项启动事件中的代码。
将 <entityNamespace>、<entityName>、<viewName> 和 <subscriptionName> 的占位符值替换为有效的值。
保存该项目。
编译并运行该项目。
这将打开 Office 应用程序并执行以下代码。
RemoteOfflineRuntime remoteOfflineRuntime = new RemoteOfflineRuntime();
// Read the subscription.
ISubscription sub =
remoteOfflineRuntime.GetSubscriptionManager().GetSubscription(
"<entityNamespace>", "<entityName>", "<viewName>", "<subscriptionName>");
// Enumerate through the Associations of the subscription, change their
// refresh interval, and enable them.
// If the properties are going to be changed for a particular Association,
// we could check the name of the subscription Association to determine
// whether the properties are to be changed.
foreach (ISubscriptionAssociation association in sub.Associations)
{
// If the subscription association is disabled, enable it.
if (association.Enabled == false)
{
association.Enabled = true;
}
// Set the refresh interval of the association.
association.ExpireAfter = TimeSpan.FromMinutes(10);
// Update the properties of the subscription association.
association.Update();
}