36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
namespace YLErp.Helpers
|
|
{
|
|
static class PathHelper
|
|
{
|
|
/// <summary>
|
|
/// 物理路径转换为web路径
|
|
/// </summary>
|
|
public static string PhysicalPathToWebPath(string physicalPath, string rootPath)
|
|
{
|
|
if (physicalPath is null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(rootPath))
|
|
{
|
|
return physicalPath.Replace('\\', '/');
|
|
}
|
|
|
|
var index = physicalPath.IndexOf("\\app_docs\\", StringComparison.OrdinalIgnoreCase);
|
|
|
|
if (index >= 0)
|
|
{
|
|
return physicalPath.Substring(index).Replace('\\', '/');
|
|
}
|
|
|
|
if (physicalPath.StartsWith(rootPath, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return physicalPath.Substring(rootPath.Length).Replace('\\', '/').Insert(0, "/");
|
|
}
|
|
|
|
throw new Exception("物理路径转换WEB路径失败,原因:物理路径应开始于传入的根目录路径");
|
|
}
|
|
}
|
|
}
|