我正在开发一个将文件保存在 Path.GetDirectoryName(FilePath)
中的应用程序,其中 FilePath = Application.ExecutablePath
包含一些有关许可的信息。如果我从 VS 运行该程序,它工作正常,但如果我制作安装程序并安装然后运行它,该程序认为该文件已经存在。我更改了我的程序以在消息框上显示我的 FilePath
以及 File.Exists(FilePath)
返回 true
还是 false
。所以我查看了那个路径,启用了显示隐藏文件和系统文件,F5 几次但没有。该文件不存在,但 File.Exists(FilePath)
返回 true。知道为什么会发生这种情况吗?我该如何解决?
我使用的是 Windows Vista、Visual Studio 2010、C# 并使用 VS 的安装项目创建了我的安装程序。
编辑:我的路径是:C:\Program Files (x86)\Helium\License.xml。
这是我的部分代码:
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
忘了说我之前已经安装了应用程序所以文件曾经存在。我使用控制面板卸载了。
最佳答案
如果您正在安装到系统文件夹,Windows 文件虚拟化可能会启动并为每个用户创建文件副本。所以你的文件可能位于 %userprofile%\AppData\Local\VirtualStore 文件夹中的某处
关于c# - File.Exists 为不存在的文件返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4308421/