转自:http://www.gaobo.info/read.php/660.htm
- string str = this.GetType().Assembly.Location;
- result: X:/xxx/xxx/xxx.exe (.exe文件所在的目录+.exe文件名)
- string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
- result: X:/xxx/xxx/xxx.exe (.exe文件所在的目录+.exe文件名)
- string str = System.Environment.CurrentDirectory;
- result: X:/xxx/xxx (.exe文件所在的目录)
- string str = System.AppDomain.CurrentDomain.BaseDirectory;
- result: X:/xxx/xxx/ (.exe文件所在的目录+"/")
- string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
- result: X:/xxx/xxx/ (.exe文件所在的目录+"/")
- string str = System.Windows.Forms.Application.StartupPath;
- result: X:/xxx/xxx (.exe文件所在的目录)
- string str = System.Windows.Forms.Application.ExecutablePath;
- result: X:/xxx/xxx/xxx.exe (.exe文件所在的目录+.exe文件名)
- string str = System.IO.Directory.GetCurrentDirectory();
- result: X:/xxx/xxx (.exe文件所在的目录)
.NET中三种获取当前路径的代码
- HttpContext.Current.Server.MapPath("FileName")
- System.Web.HttpContext.Current.Request.Path
- System.Environment.CurrentDirectory
- Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
|
请发表评论