如何获得我的项目路径?

时间:2013-01-27 17:01:11

标签: c# forms path

  

可能重复:
  get path for my .exe using c#

你好我有一个问题: 如何获得我的根项目路径?我的意思是项目中解决方案的第一个文件夹。 我找到了命令:

System.IO.Directory.GetCurrentDirectory();

然而,它为我提供了发布文件夹的特定路径: wanted_Path / bin中/释放

还有其他代码,我应该手动切割它还是将我的文件放在Release文件夹中?

4 个答案:

答案 0 :(得分:76)

这为您提供了根文件夹:

System.AppDomain.CurrentDomain.BaseDirectory

您可以使用..或./ etc ..从此处导航, 附加..将您带到可以找到.sln文件的文件夹

答案 1 :(得分:39)

您可以使用

string wanted_path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));

答案 2 :(得分:18)

var requiredPath = Path.GetDirectoryName(Path.GetDirectoryName(
System.IO.Path.GetDirectoryName( 
      System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase )));

答案 3 :(得分:6)

您的程序不知道您的VS项目在哪里,所以请参阅get path for my .exe并转到../..以获取项目的路径。

相关问题