locked
Get application name using Reflection? RRS feed

  • Question

  •  

    Is there a way to use Reflection in .NET (or any other method) to get the application name of my web app?  For example if the name of my app is 'MyWebApp' and has 10 pages within it, I would like to be able to extract the name 'MyWebApp' programatically.  Is this possible?

    Thursday, November 8, 2007 8:42 PM

Answers

  • Well I think I figured it out; here is 1 way to do it for the currently running application (Switch GetExecutingAssembly to GetCallingAssembly if you need the code that called your code)

     

    Dim AssemblyInstance As Assembly = System.Reflection.Assembly.GetExecutingAssembly()

    Dim ReturnValue As AssemblyName = AssemblyInstance.GetName

    Dim ApplicationName As String = ReturnValue.Name

     

    This was an alternative way to find it, but I could not determine when to stop looping:

     

    Dim st As StackTrace = New StackTrace(1, True)

    Dim stFrames() As StackFrame = st.GetFrames()

    Dim I As Integer

    For I = 0 To stFrames.Length - 1 Step I + 1

    Dim fa As Assembly = stFrames(I).GetMethod().DeclaringType.Assembly

    WebAssemblyName = fa.GetName().Name

    Next

     

     

    Thursday, November 8, 2007 10:20 PM