Wednesday, April 18, 2012

Create Folder in library using ECMA client object model

Here is a simple way to create folder inside library using ECMA client object model

<script type="text/javascript">
var clientcontext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(AddFolder, “sp.js”);
function AddFolder()
clientcontext = new SP.ClientContext.get_current();
web = clientcontext.get_web();
this.list = web.get_lists().getByTitle("LibraryName");
var listItemCreationInfo = new SP.ListItemCreationInformation();
var newItem = list.addItem(listItemCreationInfo);
clientcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess),
Function.createDelegate(this, this.ExecuteOnFailure));
function ExecuteOnSuccess(sender, args) {
SP.UI.Notify.addNotification('Folder has been successfully created', false);
function ExecuteOnFailure(sender, args) {
alert("Some error");

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to