I am trying to add a folder to a library on my site, however I am finding it extremely difficult to complete such a simple task. The function executes properly (no errors or exceptions) however the folder is never added and the executeQueryAsync function calls the error handler, making me think that the server denies the request.
function createFolder() {
var clientContext = SP.ClientContext.get_current();
var oWebsite = clientContext.get_web();
var oList = oWebsite.get_lists().getByTitle("Scripts Test");
var itemCreateInfo = new SP.ListItemCreationInformation();
itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
itemCreateInfo.set_leafName("My new folder!");
this.oListItem = oList.addItem(itemCreateInfo);
this.oListItem.update();
clientContext.load(this.oListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, successHandler),
Function.createDelegate(this, errorHandler)
);
}
function successHandler() {
$("#requestStatus").html("Go to the " +
"<a href='../Lists/Shared Documents'>document library</a> " +
"to see your new folder.");
}
function errorHandler() {
$("#requestStatus").html("Request Failed");
}
$("#addFolder").click(function () {
createFolder();
$("#requestStatus").html("maybe the list got updated");
return false;
});
Most of the code is taken straight from MSDN and implemented in a Visual Studio SP add in so I hesitate to think it's an issue with the code (although I would be happy if that was the problem). Could it be a problem with the server and my permissions to interact with it? Hopefully someone with SharePoint development experience can provide insight into the error.