This one had me going crazy for awhile.
I have an app that was behaving strangely and claiming files had been written when they clearly had not. It was especially confusing because when I ran this app in debug mode or the bin directory of my project it seemed to work fine. As soon as I moved it to a folder within the Program Files folder weird things started happening.
It took me awhile to track it down but for some reason when I tried to write to:
C:\Program Files\<some path>\test.txt
Using File.WriteAllText
it would instead be written to:
C:\Users\spencer\AppData\Local\VirtualStore\Program Files\<some path>\test.txt
What further confused me is that File.Exists("C:\Program Files\<some path>\test.txt")
was returning true.
This doesn't seem to happen across the board however. Another portion of my app uses the File.OpenWrite()
method which would write the file to the actual path I specified and does not toss the file into the virtual store.
EDIT: It would seem that StreamWriter
ignores the specified path and tosses files in the virtual store as well.
Is this behavior documented anywhere?