相关疑难解决方法(0)

File.Exists对于不存在的文件返回true

我的工作是保存在一个文件中的应用程序Path.GetDirectoryName(FilePath),其中FilePath = Application.ExecutablePath包含有关许可的一些信息.如果我从VS运行程序它可以正常工作,但如果我制作安装程序并安装然后运行它,程序会认为该文件已经存在.我改变了我的程序,以显示在消息框中我FilePath是否File.Exists(FilePath)返回truefalse.所以我查看了那条路径,启用了显示隐藏和系统文件,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
Run Code Online (Sandbox Code Playgroud)

忘了说我之前已经安装了应用程序,因此该文件曾经存在过.我使用控制面板卸载了.

.net c# windows filesystems windows-vista

7
推荐指数
1
解决办法
3787
查看次数

System.IO.File.Exists始终返回true

我试图检查服务器上是否存在文件,如果文件存在则警告使用,以便他可以重命名文件并再次上传.但我的代码总是返回true,即使我添加!System.IO.File.Exists

此代码适用于ASP.net webform应用程序

string filename = Path.GetFileName(FileUploadControl.FileName);
if (System.IO.File.Exists("../pdf/news/" + FileUploadControl.FileName))
{
    ViewState["_fileName"] = null;
    StatusLabel.Text = "File with this name already exsists, Please rename file and Upload gain";
}
else
{
    FileUploadControl.SaveAs(Server.MapPath("../pdf/news/") + filename);
    StatusLabel.Text = "Upload status: File uploaded!";
    //_fileName = FileUploadControl.FileName;
    ViewState["_fileName"] = FileUploadControl.FileName;
}
Run Code Online (Sandbox Code Playgroud)

我确信我做错了但却无法弄清楚是什么.

c# asp.net

0
推荐指数
1
解决办法
1261
查看次数

标签 统计

c# ×2

.net ×1

asp.net ×1

filesystems ×1

windows ×1

windows-vista ×1