How to find all Directory including sub directories in asp.net

How to find all Directory including sub directories in asp.net,subdirectory,directory,how to get files to name from the directory or subdirectory
Share it:

How to find all  Directory including subdirectories in asp.net

How to find all  Directory including sub directories in asp.net

In this article, we will see about how to get files to name from the directory or subdirectory which we assign in the directory. It’s simple to get all file's names from the directory using the DirectoryInfo class and get the all files from that directory in dot.net. we have to set for Subdirectory if there are subdirectory is there than it will not check for subdirectory it will count from the root directory only and return the file name from that root directory. Here is the demo to count from directory or subdirectory also.



Default.aspx.cs:-



protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    DirectoryInfo d = new DirectoryInfo(Server.MapPath("~/FileToRead/"));
    string d2 = d.FullName.ToString();
    List<string> Files = Directory.GetFiles(d2, "*", SearchOption.AllDirectories).ToList();
    foreach (List<string> li in Files)
    {
      Response.Write(Files[0].ToString());
    }
  }
}
Share it:

aspnet

Post A Comment:

0 comments: