【问题标题】:Is there an easy way to find the path route from one directory to another VB.NET有没有一种简单的方法可以找到从一个目录到另一个 VB.NET 的路径路径
【发布时间】:2012-01-21 02:24:19
【问题描述】:

鉴于我在路径中有一个文件:

C:\Applications\General Utils\Assembly1\Assembly1\Bin\Debug\Assembly1.dll

我正在以下路径中工作:

C:\Applications\Under Development\App1\App1\

是否有一些简单的方法可以找到从应用程序到程序集的虚线路径:

..\..\..\General Utils\Assembly1\Assembly1\Bin\Debug\Assembly1.dll

【问题讨论】:

标签: .net vb.net filesystems relative-path


【解决方案1】:
System.Uri uri1 = new Uri(@"C:\Applications\General Utils\Assembly1\Assembly1\Bin\Debug\Assembly1.dll");
System.Uri uri2 = new Uri(@"C:\Applications\Under Development\App1\App1\"); 
Uri relativeUri = uri2.MakeRelativeUri(uri1);
Console.WriteLine(relativeUri.ToString());

应该做的伎俩

【讨论】:

  • 谢谢,虽然输出是 'URI' 格式而不是文件系统格式,即正斜杠而不是反斜杠和 %20 而不是空格
  • 也许你会用 Path.GetFullPath() 得到正确格式的路径
猜你喜欢
  • 1970-01-01
  • 2011-02-13
  • 1970-01-01
  • 2012-01-26
  • 2021-06-17
  • 1970-01-01
  • 1970-01-01
  • 2019-08-09
  • 1970-01-01
相关资源
最近更新 更多