Wednesday, October 05, 2011

Listing all files inside subfolders in SharePoint

This code will loop all the files inside the all subfolders of Shared Documents library in SharePoint 2010.

public ArrayList getfilesinfoder()
{
ArrayList al1 = new ArrayList();
string[] arr = LoopAllFolder();

SPSite site = SPContext.Current.Site;
for (int i = 0; i < arr.Length; i++)
{
SPFolder cols = site.OpenWeb().GetFolder("site.Url"+/Shared%20Documents/" + arr[i].ToString());
SPFileCollection files = cols.Files;
foreach (SPFile file in files)
{
al1.Add(file.Name.ToString());
}
}
return al1;
}