namespace YLErp.Helpers { static class PathHelper { /// /// 物理路径转换为web路径 /// 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路径失败,原因:物理路径应开始于传入的根目录路径"); } } }