获取项目路径
?./當前目錄
/網站主目錄
../上層目錄
~/網站虛擬目錄
如果當前的網站目錄為E:\wwwroot???應用程序虛擬目錄為E:\wwwroot\company?瀏覽的頁面路徑為E:\wwwroot\company\news\show.asp
在show.asp頁面中使用
System.Web.HttpContext.Current.Server.MapPath("./")???返回路徑為:E:\wwwroot\company\news
System.Web.HttpContext.Current.Server.MapPath("/")????返回路徑為:E:\wwwroot
System.Web.HttpContext.Current.Server.MapPath("../")???返回路徑為:E:\wwwroot\company
System.Web.HttpContext.Current.Server.MapPath("~/")?? 返回路徑為:E:\wwwroot\company
System.Web.HttpContext.Current.server.MapPath(request.ServerVariables("Path_Info"))?
?var directoryPath = System.Web.HttpContext.Current.Server.MapPath("Precious"); ?返回路徑為:E:\wwwroot\company\news\Precious
Request.ServerVariables("Path_Translated")??
上面兩種方式返回路徑為?D:\wwwroot\company\news\show.asp
System.AppDomain.CurrentDomain.BaseDirectory
// 獲取模塊的完整路徑,包含文件名
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
// 獲取和設置當前目錄(該進程從中啟動的目錄)的完全限定目錄。
System.Environment.CurrentDirectory
// 獲取應用程序的當前工作目錄,注意工作目錄是可以改變的,而不限定在程序所在目錄。
System.IO.Directory.GetCurrentDirectory()
// 獲取和設置包括該應用程序的目錄的名稱。
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
// 獲取啟動了應用程序的可執行文件的路徑。
System.Windows.Forms.Application.StartupPath
// 獲取啟動了應用程序的可執行文件的路徑及文件名
System.Windows.Forms.Application.ExecutablePath
轉載于:https://www.cnblogs.com/tengchong/p/5415932.html
總結
- 上一篇: u盘里资料变乱码怎么办 U盘资料乱码怎么
- 下一篇: iso系统镜像文件怎么安装 iso系统如