Mat*_*att 16 .net c# path relative-path
在C#中是否存在一个方法来获得给定两个绝对路径输入的相对路径?
那就是我有两个输入(第一个文件夹作为基础),如
c:\temp1\adam\
Run Code Online (Sandbox Code Playgroud)
和
c:\temp1\jamie\
Run Code Online (Sandbox Code Playgroud)
那么输出就是
..\jamie\
Run Code Online (Sandbox Code Playgroud)
Kir*_*oll 10
不确定是否有更好的方法,但这将有效:
var file1 = @"c:\temp1\adam\";
var file2 = @"c:\temp1\jamie\";
var result = new Uri(file1)
.MakeRelativeUri(new Uri(file2))
.ToString()
.Replace("/", "\\");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
617 次 |
最近记录: |