How to create a folder in Sharepoint document library using java code and NTLM authentication? I am able to create a file but not folder.

1 Answer 1


try below code,

String req = "http://sp2k13/sites/ifsp/_api/Web/Folders/add('LibraryName/FolderName')"
NTCredentials credentials = new NTCredentials(UserName, Password, "JAVA-MACHINE-NAME", "DOMAIN");
HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(AuthScope.ANY, credentials);

ClientExecutor clientExecutor = new ApacheHttpClientExecutor(httpClient);
java.net.URI uri = new java.net.URI(req);
ClientRequestFactory fac = new ClientRequestFactory(clientExecutor, uri);

ClientRequest request = fac.createRequest(req);
request.header("content-type", "application/json;odata=verbose");
request.header("X-RequestDigest", digestValue);

ClientResponse<String> response = request.post(String.class);

if (response.getStatus() != 200) {
    throw new RuntimeException("Failed : HTTP error code : " +

Use the below links for more information,

  1. How to create a folder in Sharepoint using Java and RESTFul API?

  2. https://www.example-code.com/java/sharepoint_create_folder.asp

  3. https://stackoverflow.com/questions/1630824/sharepoint-how-to-create-a-folder-in-a-document-library-please-using-web-servic

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.