I'm trying to return the .config
files that exist in %WINDIR%\System32\inetsrv\config
.
For this I am using the following code:
DirectoryInfo configFolder = new DirectoryInfo(Environment.ExpandEnvironmentVariables("%WINDIR%") + @"\System32\inetsrv\");
FileInfo[] configFiles = configFolder.GetFiles("*.config");
This returns zero objects into configFiles
. If I use another folder (say D:\DropBox) is works fine!
This code used to work, has something changed??
Also, FileInfo fi = new FileInfo(Path.Combine(configPath, "applicationHost.config"));
returns ok, but fi.Length throws FileNotFoundException
.
Seems it must be permissions, but I can't see how to check if I have permissions when the code runs!
As I am not a developer, and I only dabble with code (mostly writing admin tools for myself), I wonder if someone can explain or point me to the correct location for the answer?
Basically, I had some code from someone else's project that worked, and copied it to my own project. I'm pretty sure it worked before, but can't be 100% certain. At that time I was running x86 Windows, but I'm now on x64.
The old code still worked, so I went through copying the settings and eventually found the solution.
Setting "Platform Target" in the Project
's Build properties
to Any CPU
(from x86) made it work. Setting it to x64 also worked, but I figure it is some security thing.
Anyway, problem solved! Thanks for all your suggestions!