AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

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

By pushpam abhishek
Listen to this article

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 this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments