C# 如何获取可执行文件路径的上上级目录

转载自:https://blog.csdn.net/weixin_28692443/article/details/88106674


   
   
   
   
  1. DirectoryInfo di = new DirectoryInfo( string.Format( @"{0}..\..\", Application.StartupPath));
  2. di.FullName

就是你想要的

..\有几个就是往回退几层

2、


   
   
   
   
  1. DirectoryInfo info = new DirectoryInfo(Application.StartupPath);
  2. String path = info.Parent.Parent.FullName;

3、

string WantedPath = Application.StartupPath.Substring(0,Application.StartupPath.LastIndexOf(@"\"));
   
   
   
   

 

你可能感兴趣的:(C#)