Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File.Exists returning true for a file that doesn't exist

I'm working on an app that saves a file in Path.GetDirectoryName(FilePath) where FilePath = Application.ExecutablePath that contains some information about licensing. If I run the program from VS it works OK but if I make an installer and install and then run it, the program thinks that the file already exists. I changed my program to show on a message box my FilePath and whether File.Exists(FilePath) returns true or false. So I looked in that path, enabled showing hidden and system files, F5'd several times and nothing. The file doesn't exist, but File.Exists(FilePath) returns true. Any idea why cold this be happening and how can I work around it?

I'm using Windows Vista, Visual Studio 2010, C# and created my installer with VS's Setup Project.

Edit: My path is: C:\Program Files (x86)\Helium\License.xml.

This is part of my code:

        MessageBox.Show("LicenseFileName: " + LicenseFileName); // LicenseFileName: C:\Program Files (x86)\Helium\License.xml
        System.Diagnostics.Process.Start(LicenseFileName);      // Nothing happens
        MessageBox.Show("File.Exists(LicenseFileName): " + File.Exists(LicenseFileName)); // File.Exists(LicenseFileName): true

Forgot to say that I already had the application installed before so the file used to exist. I uninstalled using Control Panel.

like image 640
Juan Avatar asked Nov 29 '10 21:11

Juan


1 Answers

If you are installing to a system folder, it is possible that Windows file virtualization kicked in and created a per user copy of the files. So your files may be located somewhere in %userprofile%\AppData\Local\VirtualStore folder

like image 131
skajfes Avatar answered Nov 14 '22 06:11

skajfes