C#.NET获取程序工作路径的几种方法
作者:C/S框架网  发布日期:2017/09/20 14:59:25
  C#.NET获取程序工作路径的几种方法



 

C# Code:

// 获取程序工作路径的 n 种方法。
string tmp = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
tmp = System.Environment.CurrentDirectory;
tmp = System.IO.Directory.GetCurrentDirectory();
tmp = System.Windows.Forms.Application.StartupPath;
tmp = System.Windows.Forms.Application.ExecutablePath;

//针对网站应用程序有效的 m 种方法。
tmp = System.AppDomain.CurrentDomain.BaseDirectory;
tmp = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
tmp = HttpContext.Current.Request.PhysicalApplicationPath;

AppDomain.CurrentDomain.SetupInformation.ApplicationBase此方法可使用在ASP.NET中
取代Page.Server.MapPath(),可以说这个获取路径的方法是.NET通用的获取路径方法,建议使用。


//来源:C/S框架网(www.csframework.com) QQ:1980854898


 

上一篇 下一篇