Here I have created sample that will help you out.I have used recursion.
HTML
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" EmptyDataText="No files uploaded">
<Columns>
<asp:BoundField DataField="Text" HeaderText="File Name" />
</Columns>
</asp:GridView>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] folders = Directory.GetDirectories(Server.MapPath("~/Uploads/"));
List<ListItem> files = new List<ListItem>();
files = GetFiles(folders, files);
GridView1.DataSource = files;
GridView1.DataBind();
}
}
private List<ListItem> GetFiles(string[] folders, List<ListItem> files)
{
foreach (string folder in folders)
{
string[] filePaths = Directory.GetFiles(folder);
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
string[] ChildFolders = Directory.GetDirectories(folder);
if (ChildFolders.Length > 0)
{
GetFiles(ChildFolders, files);
}
}
return files;
}
Screenshot
1)
2)