0

When I'm trying to rename sub floder, I'm getting issue mention below:

"{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Invalid request."}}}"

Code:

var itemPayload = {};
itemPayload['Title'] = "new name";
itemPayload['FileLeafRef'] = "new name";

var headers = {};
headers["Accept"] = "application/json;odata=verbose";
headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val();

$.ajax({
    type: "POST",
    url: spURL + "/_api/web/GetFolderByServerRelativeUrl('/a/b/c')/ListItemAllFields",
    data: JSON.stringify(itemPayload),
    headers: headers,
    contentType: "application/json;odata=verbose",
    success: function(response) {
        alert(response);
    },
    error: function(error) {
        debugger;
    }
});

Thanks for the help!

1

1 Answer 1

0

answer:

ExecuteOrDelayUntilScriptLoaded(UpdateListItem, "sp.js");

function UpdateListItem(){
    var clientContext;
    var oWebsite;
    var oList;

    clientContext = new SP.ClientContext.get_current();

    oWebsite = clientContext.get_web();
    oList = oWebsite.get_lists().getByTitle("DocumentLibrary");

    oListItem = oList.getItemById(1);

    this.oListItem.set_item("FileLeafRef", "Folder Name");

    this.oListItem.update();

    clientContext.load(this.oListItem);
    clientContext.executeQueryAsync(onSuccess, onFailure);
}
function onSuccess() {
        alert('Update succeeded.');
}
function onFailure(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.