如果您不介意斜杠被切换,则可以[ab]使用
Uri:
Uri file = new Uri(@"c:foobarblopblap.txt");// Must end in a slash to indicate folderUri folder = new Uri(@"c:foobar");string relativePath = Uri.UnescapeDataString( folder.MakeRelativeUri(file) .ToString() .Replace('/', Path.DirectorySeparatorChar) );作为功能/方法:
string GetRelativePath(string filespec, string folder){ Uri pathUri = new Uri(filespec); // Folders must end in a slash if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) { folder += Path.DirectorySeparatorChar; } Uri folderUri = new Uri(folder); return Uri.UnescapeDataString(folderUri.MakeRelativeUri(pathUri).ToString().Replace('/', Path.DirectorySeparatorChar));}

![获取相对于当前工作目录的路径?[重复] 获取相对于当前工作目录的路径?[重复]](http://www.mshxw.com/aiimages/31/435263.png)
