The following code snippet shows how we can find array of file names with the help of Directory.GetFiles method.
string[] filePaths = Directory.GetFiles(@"D:\Client\"); for (int i = 0; i < filePaths.Length; i++) { Response.Write(filePaths[i].ToString()); //--->Print list of files in current directory. }
if you want to Get files from directory with its all sub directories then we add a new SearchOption parameter SearchOption.AllDirectories, see this:
string[] filePaths1 = Directory.GetFiles(@"D:\Client\", "*.*", SearchOption.AllDirectories); for (int i = 0; i < filePaths1.Length; i++) { Response.Write(filePaths1[i].ToString()); }
And if you want to get folders from directory, then you can use Directory.GetDirectories method:
string[] filePaths3 = System.IO.Directory.GetDirectories("D:\\Client\\"); for (int i = 0; i < filePaths3.Length; i++) { Response.Write(filePaths3[i].ToString()); }