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? ...
随机推荐
- 突破GFW,使用node.js
原文链接:https://cnodejs.org/topic/4f9904f9407edba21468f31e 这个也是网上搜的,亲自试过,非常好用! 镜像使用方法(三种办法任意一种都能解决问题,建议 ...
- C#简易播放器(基于开源VLC)
可见光通信技术(Visible Light Communication,VLC)是指利用可见光波段的光作为信息载体,不使用光纤等有线信道的传输介质,而在空气中直接传输光信号的通信方式.LED可见光通信 ...
- 【struts2】OGNL
1 OGNL概述 OGNL是对象图导航语言Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言(Expression Language,简称为EL),通 ...
- WCF安全2-非对称加密
概述: 数字签名和加密依赖于相应的加密算法 自变量:加密前的数据.密钥 因变量:加密后的数据 加密算法分类:根据加密和解密这两种步骤采用的密钥的是否相同进行分类 相同:对称加密 不相同:非对称加密 非 ...
- Web开发入门疑问收集(不定期更新)
bootstrap container和container-fluid的区别 原始链接 container 根据显示设备满足的最小宽度,来决定实际内容宽度,是一个根据设置内容阶梯式响应的布局. 例子: ...
- OP和DBA相关的一些有用资源
最近国外blog上看到的一片资源分享博文,精而全,于是转帖分享 Must-Read Books List First of all, I would like to share a list of b ...
- iOS-微信支付(订单号重复的问题)
1. 官方文档中说过同一笔交易不能多次提交,出现这个错误让核实商户订单号是否重复提交,但是有些情况下是需要重复提交的,比如:用户微信支付的时候没有付款,直接取消了,那么订单如果已经创建了,在订单中心就 ...
- 使用autotools系列工具自动部署源代码编译安装
在Linux系统下开发一个较大的项目,完全手动建立Makefile是一件费力而又容易出错的工作.autotools系列工具只需用户输入简单的目标文件.依赖文件.文件目录等就可以比较轻松地生成Makef ...
- 【团队冲刺总结】一个编码人员的反(tu)思(cao)
消失了半个多月了啊,算算时间,好像确实有近个把月没有好好的写博客来了.我一直很想写博客的,之前有老师问过写博客的动力是什么.我想了想,我觉得可能是我比较喜欢看书吧,不管是专业书还是小说(好吧,我承认, ...
- Eclipse启动报错:A java runtime Environment(JRE) or java Development……的解决办法
第一种: 解决方法: 系统变量里设置下面: 变量名:JAVA_HOME 变量值:D:\Java\jdk1.8.0_31 变量名:CLASSPATH 变量值:.;%JAVA_HOME%\lib; 变量名 ...