【问题标题】:C#-Difference between System.CurrentDomain.AppDomain.BaseDirectory and Directory.GetCurrentDirectory()C#-System.CurrentDomain.AppDomain.BaseDirectory 和 Directory.GetCurrentDirectory() 之间的区别
【发布时间】:2017-03-18 01:49:53
【问题描述】:

谁能告诉我C#中System.CurrentDomain.AppDomain.BaseDirectoryDirectory.GetCurrentDirectory()有什么区别??

AppDomain on MSDNDirectory.GetCurrentDirectory() on MSDN

【问题讨论】:

  • 由于编辑不起作用:缺少前面的“Hello community”:/
  • 好的,不知道这个。
  • “区别”在什么方面?它们是 API 的完全不同的部分。这些值通常(但并非总是)相同。当前的“工作”目录(由GetCurrentDirectory() 返回)可以在启动进程时或从内部更改。请解释您的问题:您期望和/或担心文档尚未充分描述的差异?
  • 好的,那么我的问题是:“那两个什么时候不完全相同?”

标签: c# .net directory working-directory


【解决方案1】:

根据this question不同的是,

System.AppDomain.CurrentDomain.BaseDirectory 返回当前 目录,不是可执行位置,即从 Outlook 运行时(发送 作为 \server\folder\file.exe 的链接,它将 BaseDirectory 设置为 用户文档而不是可执行位置 来自Jakub PawlinskiDirectory.GetParent(Assembly.GetExecutingAssembly().Location) 获取当前执行程序集的父文件夹。

所以我现在使用的代码是:

string location = Assembly.GetExecutingAssembly().Location;
if (location != null)
{
    string config = Path.Combine(Directory.GetParent(location).FullName, "Config.xml"));
}

【讨论】:

    猜你喜欢
    • 2022-12-12
    • 2011-01-29
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 2010-10-23
    • 2013-05-02
    • 1970-01-01
    • 2014-02-03
    相关资源
    最近更新 更多