IT知识库 购物 网址 游戏 小说 歌词 快照 开发 股票 美女 新闻 笑话 | 汉字 软件 日历 阅读 下载 图书馆 编程 China
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
vbs/VBScript DOS/BAT hta htc python perl 游戏相关 VBA 远程脚本 ColdFusion ruby专题 autoit seraphzone PowerShell linux shell Lua Golang Erlang 其它教程 CSS/HTML/Xhtml html5 CSS XML/XSLT Dreamweaver教程 经验交流 开发者乐园 Android开发资料
站长资讯 .NET新手 ASP.NET C# WinForm Silverlight WCF CLR WPF XNA VisualStudio ASP.NET-MVC .NET控件开发 EntityFramework WinRT-Metro Java C++ PHP Delphi Python Ruby C语言 Erlang Go Swift Scala R语言 Verilog 其它语言 架构设计 面向对象 设计模式 领域驱动 Html-Css JavaScript jQuery HTML5 SharePoint GIS技术 SAP OracleERP DynamicsCRM K2 BPM 信息安全 企业信息 Android开发 iOS开发 WindowsPhone WindowsMobile 其他手机 敏捷开发 项目管理 软件工程 SQLServer Oracle MySQL NoSQL 其它数据库 Windows7 WindowsServer Linux
  IT知识库 -> SharePoint -> Creating External Lists From Code -> 正文阅读

[SharePoint]Creating External Lists From Code

Creating External Lists From Code You can create an external list based on an entity (external content type) defined in SharePoint Business Connectivity Services programmatically. All you need to do is to use the SPListDataSource class that describes the entity to be bound to the external list instance.
When creating an external list, you should use the Add method overload of the SPListCollection that has the SPListDataSource type parameter. You can find a sample for that from Frederik Prijck here.
A similar method replacing the strings with the string constants defined in the SPListDataSource.BDCProperties class:
private void CreateExternalList(SPWeb web) { SPListCollection lists = web.Lists; SPListDataSource listDataSource = new SPListDataSource(); // set up the list data source     listDataSource.SetProperty(SPListDataSource.BDCProperties.Entity, "YourBdcEntity");     listDataSource.SetProperty(SPListDataSource.BDCProperties.EntityNamespace, "YourBdc.EntityNamespace");     listDataSource.SetProperty(SPListDataSource.BDCProperties.LobSystemInstance, "YourLobSystemInstancece");     listDataSource.SetProperty(SPListDataSource.BDCProperties.SpecificFinder, "ReadItem"); // create list Guid extListGuid = lists.Add("External list title", "External list description", "extlist", listDataSource); SPList extList = lists[extListGuid]; // set other list properties     extList.OnQuickLaunch = true;     extList.Update(); }
As you can see the properties of the SPListDataSource class are not real .NET properties. Instead of calling the setter of the property, you can set the their values by calling the SetProperty method.
I felt initializing the SPListDataSource through the SetProperty method a bit cumbersome, so I’ve created an extension method for the SPListDataSource class:
public static class Extensions     { public static void Initialize(this SPListDataSource listDataSource, String entity, String entityNamespace, String lobSystemInstance, String specificFinder)         {             listDataSource.SetProperty(SPListDataSource.BDCProperties.Entity, entity);             listDataSource.SetProperty(SPListDataSource.BDCProperties.EntityNamespace, entityNamespace);             listDataSource.SetProperty(SPListDataSource.BDCProperties.LobSystemInstance, lobSystemInstance);             listDataSource.SetProperty(SPListDataSource.BDCProperties.SpecificFinder, specificFinder);         }     }
Using the new extension method makes the original code a bit more readable:
private void CreateExternalListEx(SPWeb web) { SPListCollection lists = web.Lists; SPListDataSource listDataSource = new SPListDataSource(); // set up the list data source using the extension method     listDataSource.Initialize("YourBdcEntity", "YourBdc.EntityNamespace", "YourLobSystemInstancece", "ReadItem"); // create list Guid extListGuid = lists.Add("External list title2", "External list description", "extlist2", listDataSource); // set other list properties SPList extList = lists[extListGuid];     extList.OnQuickLaunch = true;     extList.Update(); }
Remark: I found that creating the external list from code takes considerably more time than creating one from the SharePoint UI. In my test environment it was about 30 secs vs. 5 secs that is quite a big difference. Probably I should launch Reflector to see that quicker method of external list creation.
上一篇文章      下一篇文章      查看所有文章
加:2015-03-30 07:09:19  更:2017-05-16 16:24:03 
 
  SharePoint 最新文章
SharePoint 2013 Workflow Manager 1.0 卸载
SharePoint 2013 Workflow Manager 1.0 远程
SharePoint 2010 使用Install
SharePoint Online 创建和使用栏
SharePoint 2010管理中心服务器提示“需要升
SharePoint Online 创建资产库
把Sharepoint Desinger 工作流部署到生产环
Sharepoint 2013列表视图和字段权限扩展插件
笑男手札:客户的banner和logo哪里去了?
SharePoint 2013 对象模型操作"网站设
技术频道: 站长资讯 .NET新手区 ASP.NET C# WinForm Silverlight WCF CLR WPF XNA Visual Studio ASP.NET MVC .NET控件开发 Entity Framework WinRT/Metro Java C++ PHP Delphi Python Ruby C语言 Erlang Go Swift Scala R语言 Verilog 其它语言 架构设计 面向对象 设计模式 领域驱动设计 Html/Css JavaScript jQuery HTML5 SharePoint GIS技术 SAP Oracle ERP Dynamics CRM K2 BPM 信息安全 企业信息化其他 Android开发 iOS开发 Windows Phone Windows Mobile 其他手机开发 敏捷开发 项目与团队管理 软件工程其他 SQL Server Oracle MySQL NoSQL 其它数据库 Windows 7 Windows Server Linux
脚本语言: vbs/VBScript DOS/BAT hta htc python perl 游戏相关 VBA 远程脚本 ColdFusion ruby专题 autoit seraphzone PowerShell linux shell Lua Golang Erlang 其它教程
网站开发: CSS/HTML/Xhtml html5 CSS XML/XSLT Dreamweaver教程 经验交流 开发者乐园 Android开发资料
360图书馆 软件开发资料 文字转语音 购物精选 软件下载 新闻资讯 小游戏 Chinese Culture 股票 三丰软件 开发 中国文化 网文精选 阅读网 看图 日历 万年历 2018年11日历
2018-11-20 2:24:54
多播视频美女直播
↓电视,电影,美女直播,迅雷资源↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT知识库