How to enumerate the items inside a SharePoint Document Library folder

In my previous blog I have included the information for downloading files from a document library, using that code we can't download the files from a folder inside the document library, if it has. Below I am giving a work around for iterating the items inside the folder. Once if we get the files inside the folder and using the URL of that file we can download the files to our local drive using HTTPRequest and HTTPResponse & FileStream classes mentioned in my previous article.

Below I am giving the URL of the blog which will provide the information on how to download the files from a SharePoint document library.

https://blogs.msdn.com/sowmyancs/archive/2007/09/15/how-to-download-files-from-a-sharepoint-document-library-remotely-via-lists-asmx-webservice-sps-2003-moss-2007.aspx

We can implement this functionality using a SharePoint web service called SiteData.asmx which is available in the /_vti_bin/ location of the SharePoint site. Using EnumerateFolder web method we can enumerate the files or folders inside the folder in a document library. You can enhance this code for doing the enumeration more than one level by implementing your own logic. This sample code snippet of a .Net console application will just enumerate a folder and it will display the URL of the files or folders inside that folder.

First you need to add a web reference to the SiteData.asmx web service to your application. After that you have to create the instance of service class for getting the web methods.

CODE SNIPPET :

siteData.SiteData objSiteDataService = new SiteData();

objSiteDataService.Credentials = System.Net.CredentialCache.DefaultCredentials;

objSiteDataService.Url = "https://localhost:34028/sites/TestSite/_vti_bin/sitedata.asmx"; // change the URL to your sharepoint site

siteData._sFPUrl[] enArray;

objSiteDataService.EnumerateFolder("https://localhost:34028/sites/TestSite/TestT/TM", out enArray); // here I hard coded the URL of the folder in "TestT" document library

foreach(siteData._sFPUrl en in enArray)

{

if(en.IsFolder)

{Console.WriteLine(en.Url);}

}

Comments

  • Anonymous
    May 17, 2011
    I have coded in java, code are as under but i am getting a null value instead of folders info.  SiteData SiteData = new SiteData();                 String sharePointSourceURL = "Check/files";                Holder<Long> enumerateFolderResult = new Holder<Long>();                Holder<ArrayOfSFPUrl> vUrls = new Holder<ArrayOfSFPUrl>();                SiteData.getSiteDataSoap().enumerateFolder(sharePointSourceURL, enumerateFolderResult, vUrls);                System.out.println(enumerateFolderResult.value);                System.out.println(vUrls.value);                if(null != vUrls.value){                        for(SFPUrl url : vUrls.value.getSFPUrl()){                                System.out.println(url.getUrl());                                System.out.println(url.getLastModified());                                System.out.println(url.isIsFolder());                        }                } Check/files has all the files and folder. Please let me know what i am doing wrong.                        System.out.println("Folder is empty");                }

  • Anonymous
    January 23, 2015
    @Akil, i'm also getting the same problem............However, when i implement it using SOAP UI, it works perfectly.................... Is the problem with JAX-WS? If you have fixed the problem, i would appreciate your help. I've also included the authentication using binding, if that seems to be an issue.