public static string GetRelativePath(string fullPath, string basePath)
{
if (string.IsNullOrEmpty(fullPath)) throw new ArgumentNullException(nameof(fullPath));
if (string.IsNullOrEmpty(basePath)) throw new ArgumentNullException(nameof(basePath));
Uri fullUri = new Uri(fullPath);
Uri baseUri = new Uri(basePath + Path.DirectorySeparatorChar);
return Uri.UnescapeDataString(baseUri.MakeRelativeUri(fullUri).ToString())
.Replace('/', Path.DirectorySeparatorChar);
}
static void Main()
{
string fullPath = @"D:\项目\红旗\拆装\images\AS5\AS05000RM.jpg";
string basePath = @"D:\项目\红旗\拆装";
Console.WriteLine(GetRelativePath(fullPath, basePath));
}
发表评论 取消回复