Last post Apr 20, 2017 09:32 AM by Cathy Zou
Apr 19, 2017 05:11 PM|xandeq|LINK
How to get Information about Files, Folders, and subfolders and show them on a ASP.NET C# website , showing a folder image for folders and subfolders and a generic file image for all files contained in that folder and a link to open/download the file ?
Something like a file tree, that you click on the folder and it expands.
Thanks in advance!
Apr 19, 2017 05:26 PM|mgebhard|LINK
How to get Information about Files, Folders, and subfolders
Learn how to use the System.IO namespace.
and show them on a ASP.NET C# website , showing a folder image for folders and subfolders and a generic file image
You'll need to find icons. Font awesome has file images and it is free.
If this is an ASP Web Forms application you can bind the file result to a
TreeView. If this is an MVC app you can do a search from Tree View MVC for html helpers.
and a link to open/download the file
That's simply an link with an href if the files are within the application directory. Otherwise you'll need to write a bit of code related to the ASP framework you are using to stream the file back to the client. There are many examples of how to do this
on the web.
Apr 20, 2017 09:32 AM|Cathy Zou|LINK
For your problem, I make an simple. You could refer to it:
<asp:TreeView ID="TreeView1" runat="server" ExpandDepth="0" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">
<ParentNodeStyle ImageUrl="~/Images/book.png" />
<NodeStyle ImageUrl="~/Images/subfolde.jpg" />
protected void Page_Load(object sender, EventArgs e)
string maifilepath = Server.MapPath("Files");
private void ListDirectory(TreeView treeView, string path)
var rootDirectoryInfo = new DirectoryInfo(path);
private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
var directoryNode = new TreeNode(directoryInfo.Name);
foreach (var directory in directoryInfo.GetDirectories())
foreach (var file in directoryInfo.GetFiles())
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
string foldename = TreeView1.SelectedNode.Parent.Text;
filename = Server.MapPath("~//Test/Files/"+ foldename+"/" + TreeView1.SelectedValue);
file = new System.IO.FileInfo(filename);
Output screenshot as below:
For more information please refer to the following link: