I need some help to find the equivalent of App.Path and App.EXEName in VB.Net in a DLL.
Thank you for your help.
According to MSDN (App Object Changes in Visual Basic .NET), the replacement for both is
System.Reflection.Assembly.GetExecutingAssembly().Location
It contains the full path (App.Path) as well as the file name (App.EXEName). You can split the information using the helper methods from the Path class:
' Import System.Reflection and System.IO at the top of your class file
Dim location = Assembly.GetExecutingAssembly().Location
Dim appPath = Path.GetDirectoryName(location) ' C:\Some\Directory
Dim appName = Path.GetFileName(location) ' MyLibrary.DLL
UPDATE (thanks to the commenters): If you are executing this code in a DLL and you want the name of the EXE that called the DLL, you need to use GetEntryAssembly instead of GetExecutingAssembly. Note that GetEntryAssembly might return Nothing if your DLL was called from an unmanaged EXE.
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