2023年8月1日发(作者:)
物理路径,虚拟路径,物理路径与虚拟路径转换,⽂件下载⽅法1 什么是物理路径?什么是虚拟路径?(1) 例⼦: ⽤IIS举个例⼦:
WEB服务⽬录是d:路径
那么⽤HTTP访问⽹站根⽬录的时候,其实访问的是d:路径,那么其中虚拟路径就是(根),物理路径就是d:路径
(2) 我⾃⼰的理解:绝对路径⼀般都是带有磁盘完成路径, ⽽虚拟路径⼀般不带有磁盘2 程序中虚拟路径和物理路径的转化 #region 物理路径和相对路径的转换 //本地路径转换成URL相对路径
private string urlconvertor(string imagesurl1) { string tmpRootDir = h(ng());//获取程序根⽬录 string imagesurl2 = e(tmpRootDir, ""); //转换成相对路径 imagesurl2 = e(@"", @"/"); //imagesurl2 = e(@"Aspx_Uc/", @""); return imagesurl2; } //相对路径转换成服务器本地物理路径
private string urlconvertorlocal(string imagesurl1) { string tmpRootDir = h(ng());//获取程序根⽬录
string imagesurl2 = tmpRootDir + e(@"/", @""); //转换成绝对路径
return imagesurl2; } #endregion3 下载的⽅法 /// /// 获取物理地址 /// public static string MapPathFile(string FileName) { return h(FileName); } /// /// 普通下载 /// /// ⽂件虚拟路径 public static bool DownLoadold(string FileName) { bool bools = false; string destFileName = MapPathFile(FileName); if ((destFileName)) { FileInfo fi = new FileInfo(destFileName); (); eaders(); = false; Header("Content-Disposition", "attachment;filename=" +ode(eName(destFileName), 8)); Header("Content-Length", ng()); tType = "application/octet-stream"; ile(destFileName); (); (); bools = true; } return bools; } public static void ResponseFile(string path, HttpContext context) { context = t; context = t; iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; string filename = eName(path); try { iStream = new ream(path, , , ); dataToRead = ; tType = "application/octet-stream"; der("Content-Disposition", "attachment; filename=" + ode(filename,8)); while (dataToRead > 0) { if (ntConnected) { length = (buffer, 0, 10000); (buffer, 0, length); (); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } } catch (Exception ex) { (e); } finally { if (iStream != null) { (); } } } public static void ResponseFile(string path, string fileName, HttpContext context) { context = t; iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; try { iStream = new ream(path, , , ); dataToRead = ; tType = "application/octet-stream"; der("Content-Disposition", "attachment; filename=" + ode(fileName,8)); while (dataToRead > 0) { if (ntConnected) { length = (buffer, 0, 10000); (buffer, 0, length); (); (); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } } catch (Exception ex) { (e); } finally { if (iStream != null) { (); } } }
2023年8月1日发(作者:)
物理路径,虚拟路径,物理路径与虚拟路径转换,⽂件下载⽅法1 什么是物理路径?什么是虚拟路径?(1) 例⼦: ⽤IIS举个例⼦:
WEB服务⽬录是d:路径
那么⽤HTTP访问⽹站根⽬录的时候,其实访问的是d:路径,那么其中虚拟路径就是(根),物理路径就是d:路径
(2) 我⾃⼰的理解:绝对路径⼀般都是带有磁盘完成路径, ⽽虚拟路径⼀般不带有磁盘2 程序中虚拟路径和物理路径的转化 #region 物理路径和相对路径的转换 //本地路径转换成URL相对路径
private string urlconvertor(string imagesurl1) { string tmpRootDir = h(ng());//获取程序根⽬录 string imagesurl2 = e(tmpRootDir, ""); //转换成相对路径 imagesurl2 = e(@"", @"/"); //imagesurl2 = e(@"Aspx_Uc/", @""); return imagesurl2; } //相对路径转换成服务器本地物理路径
private string urlconvertorlocal(string imagesurl1) { string tmpRootDir = h(ng());//获取程序根⽬录
string imagesurl2 = tmpRootDir + e(@"/", @""); //转换成绝对路径
return imagesurl2; } #endregion3 下载的⽅法 /// /// 获取物理地址 /// public static string MapPathFile(string FileName) { return h(FileName); } /// /// 普通下载 /// /// ⽂件虚拟路径 public static bool DownLoadold(string FileName) { bool bools = false; string destFileName = MapPathFile(FileName); if ((destFileName)) { FileInfo fi = new FileInfo(destFileName); (); eaders(); = false; Header("Content-Disposition", "attachment;filename=" +ode(eName(destFileName), 8)); Header("Content-Length", ng()); tType = "application/octet-stream"; ile(destFileName); (); (); bools = true; } return bools; } public static void ResponseFile(string path, HttpContext context) { context = t; context = t; iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; string filename = eName(path); try { iStream = new ream(path, , , ); dataToRead = ; tType = "application/octet-stream"; der("Content-Disposition", "attachment; filename=" + ode(filename,8)); while (dataToRead > 0) { if (ntConnected) { length = (buffer, 0, 10000); (buffer, 0, length); (); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } } catch (Exception ex) { (e); } finally { if (iStream != null) { (); } } } public static void ResponseFile(string path, string fileName, HttpContext context) { context = t; iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; try { iStream = new ream(path, , , ); dataToRead = ; tType = "application/octet-stream"; der("Content-Disposition", "attachment; filename=" + ode(fileName,8)); while (dataToRead > 0) { if (ntConnected) { length = (buffer, 0, 10000); (buffer, 0, length); (); (); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } } catch (Exception ex) { (e); } finally { if (iStream != null) { (); } } }
发布评论