3

This is my Sharepoint site http://sp2k13/sites/ifsp/ and I would like to create a folder using Sharepoint RESTFul API with Java.

I have already gone through Working with folders and files with REST in sharepoint msdn.

But how to do it with Java? I think it will be possible.

  • Do you want to create folders in document library or lists? – Asad Refai May 4 '15 at 11:44
  • @AsadRefai in lists – Sagar Pudi May 4 '15 at 11:56
  • You need only REST solution or JavaScript Object Model is fine with you? – Asad Refai May 4 '15 at 11:57
  • 3
    @AsadRefai I am asking for REST solution – Sagar Pudi May 4 '15 at 13:08
  • In my experience, creating Folders using REST does not work correctly. When you create a Folder in SharePoint it actually creates the Folder and an associated List Item. It's the List Item that shows in the List View in the SharePoint UI. When you create a Folder using the REST API, it just creates the Folder. I've reported this issue on the Office 365 Dev User Voice. – Rob Windsor Feb 4 '16 at 23:58
1

You can do something similar as below

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());
}   

For more information go through article http://blog.ctp.com/2012/12/21/interoperability-between-java-and-sharepoint-2013-on-premises/

0

JShare uses REST protocol to access to SharePoint and Office 365.

Check this create folder example

0

I found on the net Jshare. It's Java API for Microsoft SharePoint from Independentsoft company. There is an example of creating a directory on their site.

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.