一、winform获取本程序的路径 1、获取当前目录 返回最后不带“\”的目录:如D:\WinfORM\bin\Debug System.windows.Fo
返回最后不带“\”的目录:如D:\WinfORM\bin\Debug
System.windows.Forms.Application.StartupPath;
System.Environment.CurrentDirectory;
System.IO.Directory.GetCurrentDirectory();
返回最后带“\”的目录(AppDomain应用程序域):如D:\Winform\bin\Debug\
System.AppDomain.CurrentDomain.BaseDirectory;
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
System.Windows.Forms.Application.ExecutablePath;
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
System.Reflection.Assembly.GetExecutingAssembly().CodeBase; //或者
System.Reflection.Assembly.GetAssembly(typeof(类名)).CodeBase; //利用反射获取当前程序集的位置
typeof(类名).Assembly.Location;//利用反射
虚拟目录名:WebSite1
指向:E:\mis\tools
本网页:Http://localhost/WebSite1/folder/WebForm1.aspx
根相对路径:
System.Web.HttpRuntime.AppDomainAppVirtualPath;
Request.ApplicationPath;
根绝对路径:
AppDomain.CurrentDomain.BaseDirectory;
Request.PhsicalApplicaitonPath;
Server.MapPath(“~”) \\ Server.MapPath("/WebSite1")
当前文件相对路径、绝对路径
Request.Path //相对路径 /WebSite1/folder/WebForm1.aspx
Request.PhsicalPath //绝对路径 E:\mis\tools\folder\WebForm1.aspx
Request.AppRelativeCurrentExecutionFilePath //~/folder/WebForm1.aspx
当前目录
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文件中,用”./”、”../”、”/”表示相对路径和绝对路径。
--结束END--
本文标题: C#获取应用程序路径或Web页面目录路径
本文链接: https://www.lsjlt.com/news/148746.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0