Mar*_*ram 3 c# entity-framework path winforms
好的,我正在将一些我的Winform项目从Framework 4.0移动到Framework 4.5,我遇到了一个问题,试图从类库中找到可执行路径.我有一个错误日志记录类,我用来记录错误这里是我的代码片段:
using System;
using System.IO;
using System.Windows.Forms;
namespace FunctionClassLibrary
{
public static class ErrorLogging
{
public static string errLogFullPath
{
get
{
string errLogFile = "Application";
m_errLogFullPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), errLogFile + "_ErrorLog.txt");
return m_errLogFullPath;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我能够引用System.Windows.Forms命名空间,该命名空间反过来公开Application.ExecutablePath属性.显然,在Framework 4.5中,您不能再引用System.Windows.Forms命名空间.我一直在谷歌上搜索没有成功,这两个MSDN链接:LINK1和LINK2都显示使用System.Windows.Forms命名空间的示例.所以我的问题是,是否有人有解决此问题的方法?
好吧,我正在失去理智,我只是意识到我可以简单地使用Environment.GetFolderPath方法来查找CommonProgramFiles文件夹,这是我应该存储此文件的位置.抱歉打扰每个人今天早上.
你可以使用Directory.GetCurrentDirectory()或AppDomain.CurrentDomain.BaseDirectory代替:
Path.Combine(Directory.GetCurrentDirectory(),
errLogFile + "_ErrorLog.txt");
Run Code Online (Sandbox Code Playgroud)
要么:
Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
errLogFile + "_ErrorLog.txt");
Run Code Online (Sandbox Code Playgroud)