Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

c# - 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)HeliumLicense.xml.

This is part of my code:

        MessageBox.Show("LicenseFileName: " + LicenseFileName); // LicenseFileName: C:Program Files (x86)HeliumLicense.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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%AppDataLocalVirtualStore folder


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...