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

}