Monday, 22 October 2018

Create file in SharePoint document library using REST API

Create file in SharePoint document library using REST API

$( document ).ready(function() {

    createlist();

});




function createlist()
{


var content = "Hello, this text is inside the file created with REST API";
var digest = $("#__REQUESTDIGEST").val();
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('/PerformanceDocuments/')/Files/add(overwrite=true, url='test.txt')";
jQuery.ajax({
    url: url,
    type: "POST",
    data: content,
    headers: {        
        "accept": "application/json;odata=verbose", 
        "X-RequestDigest": digest       
    },
    success: function(data){
        console.log(data);
    },
    error: function(data){
        console.log(data);
    }
});
}

No comments:

Post a Comment