views:

41

answers:

1

I'm programatically looking ito a .aspx file and getting the file class name declared in its CodeBehind. For example, when analyzing myFile.aspx I read in its Page Directive and found its CodeBehind equals "myApplication\myPage.aspx.vb". Then I use the code below:

[Code]
Dim Assm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("myApplication\bin\myApplication.dll")
Dim ClassType As Type = Assm.GetType("myApplication\myPage.aspx.vb")

' myBaseType = "myApplication.Forms.BasePage"
Dim myBaseType As System.Type = ClassType.BaseType
[/Code]

Now I want to read the BaseFile (class = myApplication.Forms.BasePage). However, to read in this file, I need I need to get its full path instead of its namespace/class hiearchy. In this case, the BasePage is wrapped in a different namespace declaration thus I cannot just change the '.' to '\'.

How can I get the path of BasePage so I can read it? Thank you - Frank

A: 

I think you need to focus on getting the 'Type' of the class regardless of location via a GetType() method, and then apply Reflection on that type to get its location. So don't concentrate on the namespace but rater the type within the BaseFile namespace. Here is some code I translated from the MSDN to get the physical location of my 'Customer' class. You should be able to use this to get the location of any binary based on its type in your application:

    Dim SampleAssembly As [Assembly]
    ' Instantiate a target object.
    Dim myType As New Customer()
    Dim Type1 As Type
    ' Set the Type instance to the target class type.
    Type1 = myType.GetType()
    ' Instantiate an Assembly class to the assembly housing the Integer type.  
    SampleAssembly = [Assembly].GetAssembly(myType.GetType())
    ' Gets the location of the assembly using file: protocol.
    Console.WriteLine(("CodeBase=" + SampleAssembly.CodeBase))

You can read up on this more at the following link:

Assembly.CodeBase Property:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.codebase.aspx

atconway
Thanx for the reply,Unfortunately, this only allows me to get the location of the .dll.I am trying to programmatically trace the sequence/hiearchy of methods that get called...and list that out (and the file names). Basically, I am trying to create a desktop application that will look into my asp.net application (via its dll or pdb) and tell me the hiearchy of methods with and their path locations. The display should be similar to the stack trace that you see when there is an error (in asp.net).
Jason