0
if (Fubrowse.HasFile)
{
  string path = Path.GetFullPath(Fubrowse.PostedFile.FileName);
  //string root = Path.GetPathRoot(path);
  GetFilesFromDirectory(path.Substring(0, path.LastIndexOf("\\")));
}
else
  GeneralClass.ShowMessageBox("Please Select File First.");
}

private void GetFilesFromDirectory(string DirPath)
{
  try
  { 
    DirectoryInfo Dir = new DirectoryInfo(DirPath);
    FileInfo[] FileList = Dir.GetFiles("*.cs", SearchOption.AllDirectories);
    foreach (FileInfo FI in FileList)

Here, path is c:\windows\system32\inetsrv\config\. I want to get all sub directories's file name in FileList array.

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
Shane
  • 31
  • 1
  • 1
  • 5
  • So.. to clarify... you want to list the files in a directory.. and this includes files from `c:\windows\system32\inetsrv\config\` folder ? – Madushan Sep 07 '12 at 05:10
  • Is the problem that you have no permission to access **all** files or **any** file at all? What happens if you only try to list files in *one* directory? Can you read the contents of **any** file what so ever? – Konrad Viltersten Oct 06 '12 at 14:54

2 Answers2

0

The Windows account that's running your code needs read access to the folder (that typically requires admin rights).

  • If you're running the program from Visual Studio, that's your account. Run VS as administrator and your code should work should work.
  • If it's a web app, the app pool account needs read access to the folder.
  • If it's a windows service, the host account needs access.
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
0

I had the same issue. I couldn't get files from the C:\Windows\system32\intesrv\config because my system was 64 bit and my request redirect to C:\Windows\SysWOW64\system32\intesrv\config More explanation is given by this answer.

PS. My answer is left here just for those who will be in search in future

Barabas
  • 912
  • 8
  • 19
  • I don't have "C:\Windows\SysWOW64\system32\intesrv\config". My system has a "C:\Windows\SysWOW64\inetsrv" directory. However, that doesn't open either. – Waldron Jul 03 '23 at 14:23