1

I my asp.net application,I have to read some file in the system32 directory.

Like

c:/windows/system32/xx.config.

But I always get the "FileNotFound" exception.

It seems that this is related to the permission problem

How to solve it?


Update

XmlDocument doc=new XmlDocument();
string file = Environment.GetFolderPath(Environment.SpecialFolder.System) +"\\inetsrv\\config\\applicationHost.config";
string dir = Environment.GetFolderPath(Environment.SpecialFolder.System) +"\\inetsrv\\config";
log.Info(Directory.Exists(dir)); // ==> true
log.Info(File.Exists(dir+"\\applicationHost.config")); // ==> false
if(File.Exist(file))
    doc.load(file);

Even I change the System to SystemX86 ,the result does not change.

Then I load the file directly without check its exist:

XmlDocument doc=new XmlDocument();
string file = Environment.GetFolderPath(Environment.SpecialFolder.System) +"\\inetsrv\\config\\applicationHost.config";
doc.load(file);

Then I got this:

Access to path "C:\Windows\System32\inetsrv\config\applicationHost.config" is denied.

It seems that the file is protected,so I try to add all the permissions(read/execute/write) for user "NetWorkService" for Both the file and its parent folder.

But the Exception is still throwed.

hguser
  • 35,079
  • 54
  • 159
  • 293
  • 2
    Post the code to verify perhaps a typo. And double check if the file is actually there. – Pedro Ferreira Apr 18 '12 at 13:36
  • I am exactly sure the file is there. – hguser Apr 18 '12 at 13:37
  • Ok then its most likely some code issues. – Pedro Ferreira Apr 18 '12 at 13:38
  • If you're in a 64 bits computer and your application is 32bits you'll have some troubles with system redirection. [Stackoverflow](http://stackoverflow.com/questions/2160699/check-if-file-exist-on-64-bits-system-using-file-exists) <- see this for possible reason – Pedro Ferreira Apr 18 '12 at 13:44
  • We can't help you unless you post some code or otherwise describe how you are attempting to access this file. – Rob Levine Apr 18 '12 at 13:47
  • I update it. And I run inthe 32bits computer – hguser Apr 18 '12 at 13:51
  • as final detail can you put a breakpoint before XmlDocument statement and provide the string "file" content? Because i think you're having the issue of the link i posted above – Pedro Ferreira Apr 18 '12 at 14:08
  • the file content is "c:/windows/system32/inetsrv/applicationHost.config" – hguser Apr 18 '12 at 14:09
  • That might be your problem.: Check this [DotNetPerls](http://www.dotnetperls.com/path) And try do this: [Code]File temp = new File(file); if(temp.exists()) Console.Write("I can see it"); [/Code] – Pedro Ferreira Apr 18 '12 at 14:18
  • @pedro:I update my post just now,can you have a check? – hguser Apr 19 '12 at 01:21
  • well, log.Info(File.Exists(dir+"\\applicationHost.config")); // ==> false means the application cannot see it! It doesnt even try to open it. My guess is the system is redirecting based on the alias to the wrong path as you can witness in the link i've posted above – Pedro Ferreira Apr 19 '12 at 08:37
  • 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](https://stackoverflow.com/a/23327624/2674033). PS. My answer is left here just for those who will be in search in future – Barabas Mar 03 '18 at 03:07

0 Answers0