SharePoint 2010: Create a List from a List Template using ECMA Script
Introduction
This article demonstrates how to create list based on various list templates using client object model JavaScript variation (ECMA Script).
Custom List
Code Sample
<input id="btnCreateCustomList" onclick="CreateCustomList()" type="button" value="Create List"/>
<script language="ecmascript" type="text/ecmascript">
var clientContext = null;
var oWeb = null;
var oListColl = null;
var oList = null;
var listCreationInfo = null;
function CreateCustomList() {
clientContext = new SP.ClientContext.get_current();
oWeb = clientContext.get_web();
listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title('Test Custom List');
listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
oList = oWeb.get_lists().add(listCreationInfo);
clientContext.load(oList);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert(oList.get_title() + ' created successfully.');
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
Document Library:
listCreationInfo.set_title('Test Custom DocumentLibrary');
listCreationInfo.set_templateType(SP.ListTemplateType.documentLibrary);
Survey
listCreationInfo.set_title('Test Custom Survey');
listCreationInfo.set_templateType(SP.ListTemplateType.survey);
Links
listCreationInfo.set_title('TestLink');
listCreationInfo.set_templateType(SP.ListTemplateType.links);
Announcement
listCreationInfo.set_title('TestAnnouncement');
listCreationInfo.set_templateType(SP.ListTemplateType.Announcements);
Contacts
listCreationInfo.set_title('TestContact');
listCreationInfo.set_templateType(SP.ListTemplateType.contacts);
Events
listCreationInfo.set_title('TestEvents');
listCreationInfo.set_templateType(SP.ListTemplateType.events);
Tasks
listCreationInfo.set_title('TestTaskList');
listCreationInfo.set_templateType(SP.ListTemplateType.tasks);
Discussion Board
listCreationInfo.set_title('TestDiscussionBoard');
listCreationInfo.set_templateType(SP.ListTemplateType.discussionBoard);
Picture Library
listCreationInfo.set_title('TestPictureLibrary');
listCreationInfo.set_templateType(SP.ListTemplateType.pictureLibrary);
Here is the list of few more list templates provided by sharepoint
for complete list templates refer below site
@ http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx