简体   繁体   中英

Access to the path 'c:\windows\system32\inetsrv\config\' is denied

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM