1

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'}");
post.setEntity(stringEntity);
post.setHeader("X-RequestDigest","xxxxxxxxxxxxxxxxxxxxxxx");
post.setHeader("Cookie",
"rtFa=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
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) {
  result.append(line);
}
System.out.println("RESULT = " + result.toString());
}

Any help would be appreciated.

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

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.