I wrote a java code to update(rename) a folder in SharePoint based on the reference in the link ( https://msdn.microsoft.com/en-us/library/office/dn292553.aspx)

Example, We are updating(renaming) a folder in SharePoint from 'Movies' to 'News'

The code get executed without Exception, but the folder didn't get updated in SharePoint.

The response returns with HTTP status code of 204(No Content)

String url = "https://siteurl/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents/Movies')";

HttpClient client = HttpClientBuilder.create().build();

HttpPost post = new HttpPost(url);

post.setHeader("X-RequestForceAuthentication", "true");

post.setHeader("Content-Type", "application/json;odata=verbose");
post.setHeader("Accept", "application/json;odata=verbose");
post.setHeader("X-HTTP-Method", "MERGE");
post.setHeader("IF-MATCH", "*");

StringEntity stringEntity = new StringEntity("{ '__metadata': { 'type': 'SP.Folder' }, 'Name': 'News'}");
HttpResponse response = client.execute(post);
System.out.println("Response Code : " + response.getStatusLine().getStatusCode());

if (response.getEntity() != null) {
BufferedReader rd = new BufferedReader(
    new InputStreamReader(response.getEntity().getContent()));

StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println("RESULT = " + result.toString());

Any help would be appreciated.

  • The post.setHeader("X-RequestDigest","xxxxxxxxxxxxxxxxxxxxxxx");, did you hide the value or you are passing that value to the rest? – Marco Mar 15 '17 at 13:52

Your Answer

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

Browse other questions tagged or ask your own question.