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?
System.Reflection.Assembly.GetExecutingAssembly().Location
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With