I want to rename folder via SharePoint Online REST API from CRM Plugin. Below is my code. I am getting HTTP 204 response, but the folder name is not changed.

Please can someone tell what is wrong with code?

I am using [SharepointSiteUrl]/_api/web/GetFolderByServerRelativeUrl('[oldFolderPath]')/ListItemAllFields

string folderUrl = SharepointUtility.GetFolderUpdateUrl(this.pluginConfiguration, oldFolderPath);

HttpWebRequest request = HttpWebRequest.Create(folderUrl) as HttpWebRequest;

request.Method = "POST";
request.Accept = "application/json;odata=verbose";
request.ContentType = "application/json;odata=verbose";
request.Headers.Add("X-RequestDigest", digestValue);
request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); 
request.Headers["X-HTTP-Method"] = "PATCH";
request.Headers["IF-MATCH"] = "*";
request.CookieContainer = authorizationCookie;

// Setting change folder data
string requestData = "{ '__metadata': { 'type': 'SP.Folder' }, 'Name': '" + newFolderName + "' }";
request.ContentLength = requestData.Length;

StreamWriter writer = new StreamWriter(request.GetRequestStream());

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
        string responseString = streamReader.ReadToEnd();
  • Check this sharepoint.stackexchange.com/questions/105408/…
    – Unnie
    Mar 31, 2016 at 14:07
  • Thanks for your answer. It does not work for me, because I need to do this from the C# code in the CRM ONLINE plugin. But I have set the request like in this post, and get the HTTP 204 response with no folder name change Mar 31, 2016 at 15:16

2 Answers 2


The endpoint you are using cannot be used to change the Name of the folder because the Name property is not editable.

  1. Make a GET request to get the item id/URI and the type of the folder.

ENDPOINT URI: <SiteURL>/_api/web/GetFolderByServerRelativeUrl('<FoldFolderPath>')/ListItemAllFields

  1. From the response of the above request, extract uri attribute value and type attribute value.

  2. Make another POST request with ENDPOINT as the uri extracted from the above step.

ENDPOINT URI format will be like: <SharepointSiteUrl>/_api/Web/Lists(guid'<Guid if list>')/Items(<id of item>)

Note: If you know the ID of the folder item, you can skip step 1.


Each folder has a list item associated with it. The way you change the name of the folder is by changing the Title and FileLeafRef field values of the associated list item (obvious - right)?

If you take a look at the code in the answer linked in Unnie's comment you can see that is what the author is doing.

Code snip


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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