Reputation: 861
I know in vb.net you can use System.Reflection.MethodInfo.GetCurrentMethod.ToString
to get the name of the current method you are in. However, is there a way to use System.Reflection...
to get the name of the current file you are in?
So if you had a file in the project named blah.vb
I would want System.Reflection...
to return blah.vb
Is this possible?
Upvotes: 1
Views: 306
Reputation: 43743
You can use System.Reflection.Assembly
to find the file name of the current assembly. There are several applicable methods to choose from:
GetEntryAssembly
- Returns the assembly that started the process (the executable)GetCallingAssembly
- Returns the assembly that called the current methodGetExecutingAssembly
- Returns the assembly in which the current method residesI suspect that what you want is GetExecutingAssembly
. All of those methods return an Assembly
object through which you can get the file path, like this:
Dim myFilePath As String = System.Reflection.Assembly.GetExecutingAssembly().Location
For what it's worth, if you need get the file name of the executable, but it's not a .NET assembly (because you're in a .NET library invoked via COM), then the above method won't work. For that, the best option would be to grab the first argument from the command line, like this: Dim myComExeFile As String = Environment.GetCommandLineArgs()(0)
Upvotes: 2