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
// 获取程序工作路径的 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
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网