C# - System.CurrentDomain.AppDomain.BaseDirectory与Directory.GetCurrentDirectory()之间的差异

时间:2016-03-18 16:20:55

标签: c# .net directory working-directory

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

请参阅AppDomain on MSDN以及Directory.GetCurrentDirectory() on MSDN

1 个答案:

答案 0 :(得分:0)

根据this question,区别在于

  

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

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

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