C#中得到可执行文件(程序)的路径和文件名

[ 2007-09-17 10:55:17 | 作者: admin ]
字号: | |
//p.s. 记一下,不然又忘记

//得到可执行文件的路径(包括名称)
string hostName = Application.ExecutablePath;

//获取最初指定程序的位置
hostName = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;

//获取程序的路径(包括名称)
hostName = System.Reflection.Assembly.GetExecutingAssembly().Location;

//获取程序的路径(不包括程序名称)
string hostName = System.Reflection.Assembly.GetExecutingAssembly().Location;
hostName = hostName.Substring(0 , hostName.LastIndexOf('\\') );

//获取程序的名称(不包括程序后缀)通常是程序集的名称,如果可执行文件改名了,就要通过分析路径得到文件名
hostName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
[最后修改由 admin, 于 2007-09-17 10:59:27]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=992

这篇日志没有评论。

此日志不可发表评论。