我试图使用下面的代码获取控制台应用程序的目录,
Assembly.GetExecutingAssembly().Location
但是这个给了我汇编所在的位置.这可能与我执行应用程序的位置不同.
我的控制台应用程序解析没有参数的日志.它必须转到logs/可执行文件夹中的文件夹,或者如果我给它一个路径来logs/解析它.
在我的ASP.NET应用程序的启动代码(即没有请求)中,我需要获取应用程序根目录的路径.我需要这个打开我在根目录下的文件夹中的文件.
我怎么能得到这个?
我有一个像以下网站项目:
namespace Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lbResult.Text = PathTest.GetBasePath();
        }
    }
}
该方法PathTest.GetBasePath()在另一个项目中定义,如:
namespace TestProject
{
    public class PathTest
    {
        public static string GetBasePath() 
        {
            return AppDomain.CurrentDomain.BaseDirectory;
        }
    }
}
为什么...\Web\在将TestProject程序集编译到bin文件夹时显示它(换句话说,它应该显示...\Web\bin在我的想法中).
如果我修改了方法,我现在遇到了麻烦:
namespace TestProject
{
    public class FileReader
    {
        private const string m_filePath = @"\File.config";
        public static string Read() 
        {
            FileStream fs = null;
            fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + m_filePath,FileMode.Open, …如果我调用文件myFile = new File('myfile.txt'); 这会被保存到哪里?
我尝试获取项目的当前目录路径。我试过:
System.IO.Directory.GetDirectoryRoot();
环境.当前目录;
System.IO.Path.GetFullPath(".\");
在所有选项中我得到:
C:\Program Files (x86)\IIS Express\
而不是项目路径。
有没有人有办法解决吗?