Use SharePoint Web Service (2): Create list

Source: Internet
Author: User

In fact, it is not difficult to create a list using web service. You can simply use the lists. addlist method.

However, this method has some limitations and there is no way to create it based on the custom list template.

If you need to automatically create a list based on a list template, I did some research and did not find any way to directly use Web Servic.

In this way, I have two ideas:

1. Use Web service to automate all operations, create a basic list, add content type, and create folders .......

In fact, I used to do this all the time.

2. Use SharePoint RPC.

This is a recent study. If you don't talk nonsense, first go to the code.

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');

 

For details about how to use SharePoint RPC and create a list, refer to the following article:

  • SharePoint RPC-Part 2
  • Newlist Method

 

Slightly explain the code. The newlist method contains four parameters: the title of the new list, the description of the new list, and an ID (I tested it, there is no limit, does not need to be the ID of the Basic Template corresponding to the custom template), custom list template file name.

If you read my code, you will find that there is an additional parameter customtemplate, which makes everything possible.

 

The origin of this parameter. If anyone is interested, leave a message and I will write it later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.