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));}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)