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) {

    var fileCollectionEndpoint = SiteURL + "/_api/web/getfolderbyserverrelativeurl('MyLibrary')/folders/add(url=\'" + foldername + "\')";
        url: fileCollectionEndpoint,
        type: "POST",
        async: false,
        headers: {
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose"
        success: function(data) {
            //alert('Folder created successfully');
   + foldername, "_blank")
        error: function(jqXHR, textStatus, errorThrown) {
            //handle error...

No comments:

Post a Comment