網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
一、Winform獲取本程序的路徑
1、獲取當(dāng)前目錄
返回最后不帶“\”的目錄:如D:\Winform\bin\Debug
System.Windows.Forms.Application.StartupPath;
System.Environment.CurrentDirectory;
System.IO.Directory.GetCurrentDirectory();
返回最后帶“\”的目錄(AppDomain應(yīng)用程序域):如D:\Winform\bin\Debug\
System.AppDomain.CurrentDomain.BaseDirectory;
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
2、獲取當(dāng)前文件路徑
System.Windows.Forms.Application.ExecutablePath;
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
System.Reflection.Assembly.GetExecutingAssembly().CodeBase; //或者
System.Reflection.Assembly.GetAssembly(typeof(類名)).CodeBase; //利用反射獲取當(dāng)前程序集的位置
typeof(類名).Assembly.Location;//利用反射
二、WebForm獲取文件路徑
虛擬目錄名:WebSite1
指向:E:\mis\tools
本網(wǎng)頁(yè):http://localhost/WebSite1/folder/WebForm1.aspx
1、獲取虛擬目錄
根相對(duì)路徑:
System.Web.HttpRuntime.AppDomainAppVirtualPath;
Request.ApplicationPath;
根絕對(duì)路徑:
AppDomain.CurrentDomain.BaseDirectory;
Request.PhsicalApplicaitonPath;
Server.MapPath(“~”) \\ Server.MapPath("/WebSite1")
2、獲取文件路徑
當(dāng)前文件相對(duì)路徑、絕對(duì)路徑
Request.Path //相對(duì)路徑 /WebSite1/folder/WebForm1.aspx
Request.PhsicalPath //絕對(duì)路徑 E:\mis\tools\folder\WebForm1.aspx
Request.AppRelativeCurrentExecutionFilePath //~/folder/WebForm1.aspx
當(dāng)前目錄
Server.MapPath(”.”)或Server.MapPath(””); //E:\mis\tools\folder
Server.MapPath(”./1.jpg”)或Server.MapPath(”1.jpg”); //E:\mis\tools\folder\1.jpg
上一目錄
Server.MapPath(”..”) // E:\mis\tools
Server.MapPath(”../1.jpg”) //(””); //E:\mis\tools\1.jpg 上一目錄下的1.JPG文件
Server.MapPath(”../..”) //C:\inputpub\wwwroot 上一目錄的上一目錄,到了頂目錄wwwroot
根目錄
Server.MapPath(”/”) //C:\inputpub\wwwroot
note:在HTML文件中,用”./”、”../”、”/”表示相對(duì)路徑和絕對(duì)路徑。
原文鏈接:https://www.cnblogs.com/springsnow/p/9434002.html
相關(guān)推薦
- 2022-10-15 Go?Excelize?API源碼閱讀GetPageLayout及SetPageMargins_Go
- 2022-05-12 HarmonyOS 頁(yè)面跳轉(zhuǎn)
- 2022-06-25 Android開發(fā)跳轉(zhuǎn)應(yīng)用市場(chǎng)進(jìn)行版本更新功能實(shí)現(xiàn)_Android
- 2023-07-15 element 確認(rèn)消息的使用步驟
- 2022-06-06 數(shù)據(jù)分析數(shù)據(jù)庫(kù)ClickHouse在大數(shù)據(jù)領(lǐng)域應(yīng)用實(shí)踐_數(shù)據(jù)庫(kù)其它
- 2022-01-02 適合初學(xué)者學(xué)習(xí)ajax表單提交的全部代碼
- 2023-06-20 IDEA中的Redis插件連接Redis服務(wù)器_Redis
- 2022-09-25 ubuntu 20.04 開機(jī)黑屏小橫杠和循環(huán)登錄
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支