可能重复:
使用c#获取我的.exe的路径
您好我有一个问题:如何获得我的根项目路径?我的意思是项目中解决方案的第一个文件夹.我找到了这个命令:
System.IO.Directory.GetCurrentDirectory();
Run Code Online (Sandbox Code Playgroud)
但它给了我一个指向release文件夹的特定路径:wanted_Path/bin/Release
那么还有其他代码,我应该手动切割它还是将我的文件放在Release文件夹中?
tak*_*ala 82
这为您提供了根文件夹:
System.AppDomain.CurrentDomain.BaseDirectory
您可以使用..或./ etc ..在此处导航,附加..将您带到可以找到.sln文件的文件夹
PaR*_*RaJ 40
您可以使用
string wanted_path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
Run Code Online (Sandbox Code Playgroud)
小智 19
var requiredPath = Path.GetDirectoryName(Path.GetDirectoryName(
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase )));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
142612 次 |
| 最近记录: |