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? ...
随机推荐
- 又是一个小正则replace
var a = "http://www.xx.com?id=111&-deb"; var b = "http://www.xx.com?-deb&id=1 ...
- apache 500错误
一直以为开了error_log,没想没有加,于是折腾了好久. 开启error_log后,发现是xdebug的max_nesting_level值太小了. 还一个原因是.htaccess文件中的 < ...
- WPF小记——DockPanel使用不当引起界面显示问题
使用以下代码,当TextBlock文本过长,引起Button的显示位置在可见区域以外: <Window x:Class="WpfApplication11.MainWindow&quo ...
- Java 集合系列14之 Map总结(HashMap, Hashtable, TreeMap, WeakHashMap等使用场景)
概要 学完了Map的全部内容,我们再回头开开Map的框架图. 本章内容包括:第1部分 Map概括第2部分 HashMap和Hashtable异同第3部分 HashMap和WeakHashMap异同 转 ...
- SharePoint 2013 搜索爬网功能
最近在政府部门介绍SharePoint 2013 新功能,我也准备了很多,比如SharePoint 2013的Search.以后有机会谈谈Office Web App,Workflow等. Share ...
- [linux]删除目录下的一类文件
find 目录 -name "*.类型" | xargs rm -f 通过find命令,查找指定目录下的某一类型的文件.并通过管道传递给xargs,执行后面的rm -f命令. 最终 ...
- UWP开发入门(十六)——常见的内存泄漏的原因
本篇借鉴了同事翔哥的劳动成果,在巨人的肩膀上把稿子又念了一遍. 内存泄漏的概念我这里就不说了,之前<UWP开发入门(十三)——用Diagnostic Tool检查内存泄漏>中提到过,即使有 ...
- 一个python爬虫小程序
起因 深夜忽然想下载一点电子书来扩充一下kindle,就想起来python学得太浅,什么“装饰器”啊.“多线程”啊都没有学到. 想到廖雪峰大神的python教程很经典.很著名.就想找找有木有pdf版的 ...
- 整理的有用的一些EF的CommonDAL小封装
CommonDAL封装: using System; using System.Collections.Generic; using System.Data.Entity; using System. ...
- 关于VS2010中的TraceDebugging文件夹浅说
最近一段时间发现C盘莫名其妙的变小了,各种清理各种卸载还是没有.最后只能一个文件夹一个文件夹的找,最后针对“C:\ProgramData”(win7系统)文件夹,发现这个文件夹有3.9GB大小.然后一 ...