title: Download files from sharepoint with Java
body: <p>I am new to Sharepoint and I am trying to write a java program to process csv files which are stored in sharepoint document library. I learned that there is a new REST API for sharepoint but it seems that it needs an authentication with app registration, but I don't have admin permission on that sharepoint site so I cannot use the REST API (?). Therefore I choose to use soap. </p>
  
  <p>The url for that document library page is like: </p>
  
  <pre><code>http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Forms/AllItems.aspx?RootFolder=%2Fsites%2Fpitpublishing%2Fsales%2FManagement_Distribution%2FClar_Data&amp;FolderCTID=0x012000C12183D9A264144BBD3D315xxxxxxx&amp;View={F7D1xxx-62FD-428B-80EE-C44xxxxxx} 
  </code></pre>
  
  <p>I am so confused about sharepoint consuming with soap. I have downloaded the wsdl files from </p>
  
  <pre><code>http://sharepoint/sites/pitpublishing/sales/_vti_bin/copy.asmx?WSDL
  </code></pre>
  
  <p>and created the stubs for them. I think there should be a method like getDocumentLibrary(), which directory manipulates the document library, but I only find something relates to List, Copy and View, and many relates to List. I don't know what parameters I should provide them, I have tried </p>
  
  <pre><code>http://sharepoint/sites/pitpublishing/sales/Management_Distribution
  </code></pre>
  
  <p>but always get error at getListItems():</p>
  
  <pre><code>SEVERE: Exception. See stacktrace.javax.xml.ws.soap.SOAPFaultException: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
  </code></pre>
  
  <p>If I set the List name with a list under the same site, getListItems() will return null.</p>
  
  <p>Is there anyone who can help me out? Thank you very much!</p>
  
  <p>EDIT:</p>
  
  <p>The code that I was using is actually a tutorial code from <a href="https://davidsit.wordpress.com/2010/02/10/reading-a-sharepoint-list-with-java-tutorial/" rel="nofollow">this blog</a> .</p>
  
  <pre><code>public static void main(String[] args) {
  //      if(args.length != 3) {
  //          logger.log(Level.SEVERE, "This must be called with parameters: &lt;userId&gt; &lt;password&gt; &lt;config file path&gt;");
  //          return;
  //      }
  
      try {
          String userId = args[0];
          String password = args[1];
          WatcherConfig config = WatcherConfig.loadConfig("C:\\Desktop\\sharepoint\\watcherConfig.xml");//; //args[2];args[2]);
          Authenticator.setDefault(new FnmAuthenticator(userId, password));
  
          Lists stub1 = new Lists(config.getListsWsdlUrl());
          ListsSoap listService = stub1.getListsSoap();
          List&lt;SPDocument&gt; docs = getDocuments(listService, config.getListName(), null, "100");
  
          Copy stub2 = new Copy(config.getCopyWsdlUrl());
          CopySoap copyService = stub2.getCopySoap();     
  
          //process document
          for(SPDocument doc: docs) {
              //make sure we download all attachments first
              if(!doc.isEmail())
                  processDocument(listService, copyService, config, doc);
          }
  
          for(SPDocument doc: docs) {
              //after we download all attachments, we process the emails.
              if(doc.isEmail())
                  processDocument(listService, copyService, config, doc);
          }
      } catch (Exception e) {
          System.out.println(e);
          System.exit(1);
      }
  }
  </code></pre>
  
  <p>and a part of getDocuments() is here:</p>
  
  <pre><code>public static List&lt;SPDocument&gt; getDocuments(ListsSoap port, String listName,
          ArrayList&lt;String&gt; listColumnNames, String rowLimit) {
  
      List&lt;SPDocument&gt; docs = new ArrayList&lt;SPDocument&gt;();
  
      if (port != null &amp;&amp; listName != null 
              &amp;&amp; rowLimit != null) {
  
          try {
              // Here are additional parameters that may be set
              String viewName = "{534xxxx-4D8B-4B1D-91E3-D2ECB6xxxxx}";
              GetListItems.ViewFields viewFields = null;
              GetListItems.Query query = null;
              GetListItems.QueryOptions queryOptions = null;
              String webID = "";
  
              // Calling the List Web Service
              GetListItemsResponse.GetListItemsResult result = port
                      .getListItems(listName, viewName, query, viewFields,
                              rowLimit, queryOptions, webID);
  
              Object listResult = result.getContent().get(0);
              ......
  </code></pre>
  
  <p>Watcherconfig.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;ns2:watcherConfig xmlns:ns2="com.fanniemae.integration.sharepoint.clients"&gt;
  &lt;dispatcherList&gt;
      &lt;dispatcherConfig matchingPattern="*" invokingCommand="D:\java\jdk15\bin\java.exe"/&gt;
  &lt;/dispatcherList&gt;
  &lt;spDocumentArchiveUrl&gt;http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Clari_Data&lt;/spDocumentArchiveUrl&gt;
  &lt;spDocumentInUrl&gt;http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Clari_Data&lt;/spDocumentInUrl&gt;
  &lt;documentWorkingDir&gt;C:\Desktop\sharepoint&lt;/documentWorkingDir&gt;
  
  &lt;listsWsdlPath&gt;C:\Desktop\sharepoint\Lists.wsdl&lt;/listsWsdlPath&gt;
  &lt;copyWsdlPath&gt;C:\Desktop\sharepoint\Copy.wsdl&lt;/copyWsdlPath&gt;
  &lt;viewsWsdlPath&gt;C:\Desktop\sharepoint\Views.wsdl&lt;/viewsWsdlPath&gt;
  
  &lt;rowLimit&gt;100000&lt;/rowLimit&gt;
  </code></pre>
  
  <p></p>