使用SharePoint Web Service(2):创建List
2011-04-17 01:00
387 查看
实际上,对于使用Web Service创建List,则没有什么难度,直接使用Lists.AddList方法就可以了。
不过这个方法有个局限,没有办法根据自定义的List模板去创建。
如果需要根据一个List模板去自动化创建List,我做了下研究,也确实没发现什么可以直接用Web Servic的方法。
这样我就有2种思路:
1. 完全用Web Service去自动化所有操作,创建基本List,增加Content Type, 创建文件夹……。
事实上,我以前一直都是这么做的,囧。
2. 使用SharePoint RPC。
这个是最近研究出来的,废话不说,先上代码。
关于如何使用SharePoint RPC和创建List的方法,可以参考下面文章:
SharePoint RPC – Part 2
NewList Method
稍微解释下代码,NewList方法包含4个参数,依次为:新列表的标题,新列表的描述,一个ID(我的测试下来,没什么限制,不需要是自定义模板对应基本模板的ID),自定义列表模板文件名。
如果你看了我的代码,你会发现最后多了一个没有任何文档介绍的参数:CustomTemplate,就是这个参数使得一切变为可能。
这个参数的来历,如果有人有兴趣,就留言吧,我会在以后写出。
不过这个方法有个局限,没有办法根据自定义的List模板去创建。
如果需要根据一个List模板去自动化创建List,我做了下研究,也确实没发现什么可以直接用Web Servic的方法。
这样我就有2种思路:
1. 完全用Web Service去自动化所有操作,创建基本List,增加Content Type, 创建文件夹……。
事实上,我以前一直都是这么做的,囧。
2. 使用SharePoint RPC。
这个是最近研究出来的,废话不说,先上代码。
String.prototype.format = function(){ var agrus = arguments; return this.replace(/\{(\d+)\}/g, function (m,i){ return agrus[i]; }); } function NewList(title, description, templateID, customTemplateName){ var rpcString = 'Cmd=NewList&Title={0}&Description={1}&ListTemplate={2}&CustomTemplate={3}'; rpcString = rpcString.format(title, description, templateID, customTemplateName); var rpcResult = $.ajax({ url: Web_Server_Relative_Url+'/_vti_bin/owssvr.dll', type: 'POST', beforeSend: function(xhr) { xhr.setRequestHeader('X-Vermeer-Content-Type', 'application/x-www-form-urlencoded'); }, data: rpcString, async: true, contentType: 'application/x-www-form-urlencoded' }); rpcResult.success(function(data, textStatus, jqXHR){ }).error(function(jqXHR, textStatus){ }); return rpcResult; } NewList('Test001', '', '100', 'C1.stp');
关于如何使用SharePoint RPC和创建List的方法,可以参考下面文章:
SharePoint RPC – Part 2
NewList Method
稍微解释下代码,NewList方法包含4个参数,依次为:新列表的标题,新列表的描述,一个ID(我的测试下来,没什么限制,不需要是自定义模板对应基本模板的ID),自定义列表模板文件名。
如果你看了我的代码,你会发现最后多了一个没有任何文档介绍的参数:CustomTemplate,就是这个参数使得一切变为可能。
这个参数的来历,如果有人有兴趣,就留言吧,我会在以后写出。
相关文章推荐
- 使用SharePoint Web Service(1):创建子站点
- 使用Visual Studio 2005扩展创建Windows SharePoint Services 3.0 Web Part
- 使用SharePoint Web Service(3):删除子站点
- Sharepoint学习笔记---SPList--使用Linq to Sharepoint间接查询External List(1.通过BCS创建External List)
- 使用JQuery调用SharePoint Web Service
- 使用SharePoint Web Serivce(1)--Add a NEW item to a list.
- 使用SharePoint Web Serivce(2)--Update Delete a item in a list
- 在LINQ to SharePoint中使用创建时间,创建者,修改时间,修改者
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序 WOPI和新的Office Web Apps Server
- Sharepoint学习笔记---SPList--使用Linq to Sharepoint间接查询External List(2.复制External List内容)
- Wss3入门(1):一步一步使用Windows SharePoint Service 3.0搭建Blog网站
- Creating Your Own Document Management System With SharePoint 使用SharePoint创建你自己的文档管理系统
- SharePoint Web Service系列:编写自定义SharePoint Web Services之一
- SharePoint Web Service系列:获取文档的属性信息
- 使用 Apache Axis2 和 Eclipse 创建 Java Web Service
- SharePoint Web Service系列:编写自定义SharePoint Web Services
- 如何使用dac获取sharepoint list的数据
- 用SharePoint Designer 创建Business Data Connectivity Service进行外部数据的连接
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第13章节--使用业务连接服务创建业务线解决方式
- SharePoint Online 创建和使用视图