zoukankan      html  css  js  c++  java
  • 使用SharePoint Web Service(2):创建List

    实际上,对于使用Web Service创建List,则没有什么难度,直接使用Lists.AddList方法就可以了。

    不过这个方法有个局限,没有办法根据自定义的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的方法,可以参考下面文章:

    稍微解释下代码,NewList方法包含4个参数,依次为:新列表的标题,新列表的描述,一个ID(我的测试下来,没什么限制,不需要是自定义模板对应基本模板的ID),自定义列表模板文件名。

    如果你看了我的代码,你会发现最后多了一个没有任何文档介绍的参数:CustomTemplate,就是这个参数使得一切变为可能。

    这个参数的来历,如果有人有兴趣,就留言吧,我会在以后写出。

  • 相关阅读:
    2015 多校联赛 ——HDU5389(dp)
    spring MVC配置详解
    面试题整理11
    面试题整理09
    Spring和SpringMVC的区别
    SpringMVC01
    js中typeof与instanceof用法小记
    Java 可变参数
    log4j文件的配置
    Hibernate 分组查询 子查询 原生SQL
  • 原文地址:https://www.cnblogs.com/lambertqin/p/2018628.html
Copyright © 2011-2022 走看看