c# - 文件存在于 WPF 中

标签 c#

if (!File.Exists("SomeFile.exe"))
{
//Does not exists
}

我在与 exe 相同的路径中有 SomeFile.exe,但结果是不存在。

Windows 窗体中不会发生这种情况,有什么变化吗?

最佳答案

试试这个来获取可执行文件目录中的文件。

string directory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string filePath = Path.Combine(directory, "SomeFile.exe");

if (!File.Exists(filePath))
{
    // 1337 code here plx.
}

关于c# - 文件存在于 WPF 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1356427/

相关文章:

c# - 带有 WHERE 条件的 XElement LINQ 失败

c# - Console.WriteLine() 在发布期间写入什么?

c# - 限制 Web 客户端使用 wifi 或以太网,反之亦然

c# - 我可以使用 lambda 来简化吗?

c# - 为 "asp-for"HTML 标记指定格式 (ASP.NET Core)

c# - 当我不将 .Save() 的位图 .Dispose() 到 MemoryStream 时,为什么会发生内存泄漏?

c# - 转换器不能应用于需要类型 System.Windows.Data.IValueConverter 的属性

c# - 使用 .NET 进行 Excel 文件解析/抓取

c# - 功能(): this(null) {}

c# - 在 WPF 中更改 EventTrigger 上的按钮背景颜色