Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get FileInfo On Itself?

Tags:

c#

.net

fileinfo

My C# program is in the form of a single .exe file. Therfore, the user can store it anywhere and name it anything. How can I use the FileInfo class to get its Attributes if I don't know the path?

like image 681
Sonic42 Avatar asked Dec 06 '25 10:12

Sonic42


2 Answers

System.Reflection.Assembly.GetExecutingAssembly().Location
like image 113
neeKo Avatar answered Dec 08 '25 01:12

neeKo


using System.Diagnostics;

var info = new FileInfo(Process.GetCurrentProcess().MainModule.FileName);

PS: this will return you a path to an executable even this code snipped has been calles in one of the solution's project (DLL) but please be aware that in case of run within the VS debugger it returns ApplicationExeName.vshost.exe so in this case you might found more useful solution of Niko Drašković (System.Reflection.Assembly.GetExecutingAssembly().Location)

like image 42
sll Avatar answered Dec 07 '25 23:12

sll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!