是什么让在.NET中执行exe文件的路径最好的方法是什么?最好的、路径、文件、方法

2023-09-02 02:09:44 作者:签约ε昨天

从程序A.EXE位于C:/ DIR我需要打开文本文件C:/dir/text.txt。我不知道在哪里A.EXE可以位于,但的text.txt总是会在相同的路径。如何获得当前执行的程序集的名称从内部程序本身,这样我可以访问该文本文件?

From program a.exe located in c:/dir I need to open text file c:/dir/text.txt. I don't know where a.exe could be located, but text.txt will always be in the same path. How to get the name of the currently executing assembly from within to program itself so that i can access the text file?

修改: 如果a.exe的是Windows服务?它没有应用,因为它不是Windows Applicaion

EDIT: what if a.exe is a Windows service? It doesn't have Application as it is not a Windows Applicaion.

在此先感谢。

推荐答案

我经常访问包含我的应用程序的.exe的目录:

I usually access the directory that contains my application's .exe with:

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);