Thursday, 13 October 2011

Retrieve list of libraries on SharePoint site

In order to retrieve list of libraries on SharePoint site, please use following code:

private List getLibraries(String site, String username, String password) {
     List tag = new ArrayList();
     try {
      ListsSoapStub stub = SharePointWSDL.newLists(new URL(site + "/_vti_bin/Lists.asmx"), new ListsLocator());
      stub.setUsername(username);
      stub.setPassword(password);
      com.microsoft.schemas.sharepoint.soap.GetListCollectionResponseGetListCollectionResult lcr = stub.getListCollection();
      if (lcr.get_any().length > 0) {
          NodeList children = lcr.get_any()[0].getChildNodes();
          for (int i = 0; i < children.getLength(); i++) {
           Node node = children.item(i);
           String baseType = node.getAttributes().getNamedItem("BaseType").getNodeValue();
           if (!"1".equals(baseType)) continue;
           String template = node.getAttributes().getNamedItem("ServerTemplate").getNodeValue();
           String title = node.getAttributes().getNamedItem("Title").getNodeValue();
           if ("|101|115|109|".indexOf("|" + template + "|") < 0) continue;
           tag.add(title);
          }
      }
     } catch (Exception e) {
      logger.error("", e);
     }
     return tag;
    }
Above code use Java WSDL for SharePoint

No comments:

Post a Comment