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
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);
httpClient.getParams().setAuthenticationPreemptive(true);
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);
request.accept("application/json;odata=verbose");
ClientResponse<String> response = request.post(String.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " +
response.getStatus());
}
Use the below links for more information,