pis*_*hio 64 .net c# filesystems
从位于c:/ dir的程序a.exe我需要打开文本文件c:/dir/text.txt.我不知道a.exe的位置,但text.txt将始终位于同一路径中.如何从内部获取当前正在执行的程序集的名称到程序本身,以便我可以访问该文本文件?
编辑:如果a.exe是Windows服务怎么办?它没有应用程序,因为它不是Windows应用程序.
提前致谢.
Tim*_*ren 130
我通常访问包含我的应用程序的.exe的目录:
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
Run Code Online (Sandbox Code Playgroud)
Win*_*ith 13
string exePath = Application.ExecutablePath;
string startupPath = Application.StartupPath;
Run Code Online (Sandbox Code Playgroud)
编辑 - 不使用应用程序对象:
string path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );
Run Code Online (Sandbox Code Playgroud)
有关详情,请参阅此处:
http://msdn.microsoft.com/en-us/library/aa457089.aspx
| 归档时间: |
|
| 查看次数: |
65641 次 |
| 最近记录: |