Create a list or document library using JSOM in SharePoint online or SharePoint 2013

We can create a list or a document library using custom code, there may be several scenarios where we need to implement this using custom code.




HTML Code -

<storng><span>Please Entry Document Library Name</span></storng><br>
<input type="text" id="txtDocLibName"><br>            

<input type="button" id="btnCreateDocLib" value="Submit">

Custom Code -

$(document).ready(function() {
     $("#btnCreateDocLib").click(function () {              
          createDocLib();  
     }); 
});
function createDocLib() {                 

context = SP.ClientContext.get_current();
web = context.get_web();
list = web.get_lists();
docLibCreation = new SP.ListCreationInformation(); 
docLibName=document.getElementById("txtDocLibName").value;
docLibCreation.set_title(docLibName);
docLibCreation.set_templateType(SP.ListTemplateType.documentLibrary);
list.add(docLibCreation);
context.load(list);
context.executeQueryAsync(onDocLibCreationSuccess, onDocLibCreationFail);
        } 

function onDocLibCreationSuccess() {
            alert(docLibName +" " +"Document Library" + " " +"Created");            

}
function onDocLibCreationFail(sender, args) {
         alert('Failed to Create the Document Library. Error:' + args.get_message());
         



  

Comments

Popular posts from this blog

How to Customize exported excel's cell background color in Datatables

Populate dropdown using jquery ajax in SharePoint

Customizing SharePoint list and implementing Quick search using jQuery