代码段:获取服务器上的外部列表中的所有项的 BdcIdentity
上次修改时间: 2010年4月19日
适用范围: SharePoint Server 2010
本文内容
说明
先决条件
使用此示例
说明
以下代码段演示如何获取外部列表中所有项的 BdcIdentity。
先决条件
Microsoft SharePoint Server 2010 或 Microsoft SharePoint Foundation 2010 位于服务器上。
Microsoft Visual Studio。
至少在 BDC 元数据存储中注册一个外部内容类型,并且有一个外部列表基于该外部内容类型。
备注
此示例中使用的外部列表无法使用传递身份验证。
使用此示例
启动 Visual Studio 并创建一个 C# 控制台应用程序项目。在创建此项目时,请选择".NET Framework 3.5"。
从"视图"菜单中,单击"属性页"以显示项目属性。
在"生成"选项卡中,为"目标平台"选择"任何 CPU"。
关闭项目属性窗口。
在"解决方案资源管理器"中的"引用"下,删除 System 和 System.Core 之外的所有项目引用。
将以下引用添加到项目中:
Microsoft.SharePoint
System.Web
将 Program.cs 中自动生成的代码替换为此过程结束时列出的代码。
使用有效值替换 <siteUrl> 和 <ExternalListName> 字符串值。
保存项目。
编译并运行项目。
using System;
using System.Web;
using Microsoft.SharePoint;
namespace Microsoft.SDK.SharePoint.Samples.Bdc.ExternalList
{
class Program
{
static void Main(string[] args)
{
using(SPSite site = new SPSite("<siteUrl>"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
SPServiceContextScope contextScope = new SPServiceContextScope(context);
SPWeb web = site.OpenWeb();
SPList list = web.Lists["<ExternalListName>"];
foreach (SPListItem item in list.Items)
{
Console.WriteLine( item["BdcIdentity"]);
}
}
}
}
}