How to get files in a directory or folder in C#.Net | Asp.Net

By
Advertisement

Introduction:
In my previous article I have explained about how to get subdirectories or sub folders from a directory in C#.Net or ASP.Net. In this article I am going to explain about how to get all files in a directory using C#.Net and Asp.Net.

Explanation:
GetFiles method in the System.IO.Directory class is used for getting all the files from a directory. Below sample code gets all files from a specified folder and prints It in the web page.

protected void Page_Load(object sender, EventArgs e)
{
    string rootFolder = @"E:\FileFolder\";
    string[] files = Directory.GetFiles(rootFolder);
    foreach (string file in files)
        Response.Write(file+"<br/>");
}

Do you like this article? Help us to improve. Please post your comments below.

0 comments:

Post a Comment

Online Casino