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.
Creating External Lists From Code的更多相关文章
- leetcode -- Merge k Sorted Lists add code
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. [ ...
- Creating External Table - KUP-04020
原因:因为操作系统环境不同,所以换行符也不同,要查看数据文件的换行符 解决方法: 1.如果是苹果系统类的数据文件,则改为:RECORDS DELIMITED BY 0X'0D' 2.如果是window ...
- Searching External Data in SharePoint 2010 Using Business Connectivity Services
from:http://blogs.msdn.com/b/ericwhite/archive/2010/04/28/searching-external-data-in-sharepoint-2010 ...
- Comparing Code Playgrounds Codepen, JSFiddle, JS Bin, Dabblet, CSS Deck, and Liveweave
What is a code playground? Codepen, JSFiddle, JS Bin, Dabblet, CSS Deck, and Liveweave are HTML, CSS ...
- Sharepoint 问题集锦 - external list (外部列表)
使用Sharepoint开发过程中遇到的问题总结. 错误1: Unable to display this Web Part. To troubleshoot the problem, open th ...
- Sharepoint 问题集锦 - 外部列表(external list) - 读取当前用户上下文或用户名作为筛选参数
在创建外部列表过程中,往往需要添加筛选参数,而较多开发用户,会关心如何在外部列表中,只显示当前用户相关的行.本例子中,我们以任务数据表来做例子,看看如何实现这个需求. 1)数据表tbl_task: t ...
- 管理外部表(External Tables)
Oracle数据库允许对外部表中的数据进行只读访问.外部表定义为不驻留在数据库中的表,并且可以是为其提供访问驱动程序的任何格式.通过为数据库提供描述外部表的元数据,数据库能够公开外部表中的数据,就好像 ...
- Entity Framework Code-First(5):Code First Conventions
Code First Conventions: We have seen how EF Code-First creates DB tables from domain classes in the ...
- 转:Busy Developers' Guide to HSSF and XSSF Features
Busy Developers' Guide to Features Want to use HSSF and XSSF read and write spreadsheets in a hurry? ...
随机推荐
- [C#]LDAP验证用户名和密码
测试环境:VS2008, NET Framework 3.5 公司打算改用LDAP来存储用户名和密码,现在用C#测试下如何能拿到LDAP中的用户名,并检测用户密码是否正确.即输入用户名和密码,可以检验 ...
- How ADB works
ADB (Android Debug Bridge): How it works? 2012.2.6 early draft Tetsuyuki Kobayashi What is ADB? If y ...
- 深入研究 蒋金楠(Artech)老师的 MiniMvc(迷你 MVC),看看 MVC 内部到底是如何运行的
前言 跟我一起顺藤摸瓜剖析 Artech 老师的 MiniMVC 是如何运行的,了解它,我们就大体了解 ASP.NET MVC 是如何运行的了.既然是“顺藤摸瓜”,那我们就按照 ASP.NET 的执行 ...
- 跨域名 Cookie 传递测试
问题 我打开了 www.aaa.com 里面的一个页面(www.aaa.com/hello.php),其中这个 hello.php 里面包含一个 <img> 标签,里面的 src 来自于 ...
- 关于全局唯一ID生成方法
引:最近业务开发过程中需要涉及到全局唯一ID生成.之前零零总总的收集过一些相关资料,特此整理以便后用 本博客已经迁移至:http://cenalulu.github.io/ 本篇博文已经迁移,阅读全文 ...
- intellij 调试方法
intellij 调试方法 转自 http://www.th7.cn/Program/net/201410/296492.shtml
- Android 学习笔记之AndBase框架学习(四) 使用封装好的函数实现单,多线程任务
PS:Force Is Meaningless Without Skill 学习内容: 1.使用AndBase实现单线程任务... 2.使用AndBase实现多线程任务... AndBase内部封 ...
- Android 简单计算器源码....
PS:今天算是闲着没事做了一个小型的计算器...顺便熟悉一下Android的布局,组件,以及时间监听的方法...就当是做了一个小小的练习吧... 顺便去对比了一下别人写的代码...有的使用到了 ...
- UWP开发入门(十五)——在FlipView中通过手势操作图片
本篇的最终目的,是模拟系统的照片APP可以左右滑动,缩放图片的操作.在实现的过程中,我们会逐步分析UWP编写UI的一些思路和技巧. 首先我们先实现一个横向的可以浏览图片的功能,也是大部分APP中的实现 ...
- 设计模式--建造者(Builder)模式
将一个复杂的构建与其表示相分离,使得同样的构建过程可以创建不同的表示 --<设计模 ...