Friday 15 September 2017

Add folder in SharePoint document Library using REST


Below is the function to add folder in document library

My Business Case : I need to attach files in my custom angularjs form, so i used document library to create folder then attach files in that folder.


CreateFolder("TestFolder") ;

function CreateFolder(foldername) {
    //debugger;

    //alert(fileCollectionEndpoint);
    var fileCollectionEndpoint = SiteURL + "/_api/web/getfolderbyserverrelativeurl('MyLibrary')/folders/add(url=\'" + foldername + "\')";
    $.ajax({
        url: fileCollectionEndpoint,
        type: "POST",
        async: false,
        headers: {
            "X-RequestDigest": window.top.$("#__REQUESTDIGEST").val(),
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose"
        },
        success: function(data) {
            //alert('Folder created successfully');
            window.open(AddAttachmentURL + foldername, "_blank")
        },
        error: function(jqXHR, textStatus, errorThrown) {
            //handle error...
            alert(jqXHR.responseText);
        }
    });
}

No comments:

Post a Comment