.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Creating List in SharePoint Using Client object Model

Posted By:Nagarajan       Posted Date: December 17, 2013    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

This code is used to create a list in SharePoint using Client Object Model.

Let me give the code to create a list using Client Object Model. You need to write a code in Javascript to acheive this.

var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();
var web = context.get_web();

<script type="text/javascript">
// Creating List
function createlist() {
        var listCreationInfo = new SP.ListCreationInformation();
        listCreationInfo.set_title('Your List Name'); // List Name
        listCreationInfo.set_templateType(SP.ListTemplateType.genericList); // List Type
        lists = web.get_lists();
        var newList = lists.add(listCreationInfo);
        context.executeQueryAsync(onListCreationSuccess, onListCreationFail);
//Async Success/ Failure

 function onListCreationSuccess() {
alert('List is created successfully'); }

 function onListCreationFail(sender, args) {
  alert('Failed to create the list. ' + args.get_message());}

Happy Coding :) 


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend