Use System.Reflection to get page namespace

  • Thread starter Thread starter Joel Leong
  • Start date Start date
J

Joel Leong

How can I use Reflection to get full namespace of my web page?

I got a page under this namespace

namespace CompanyABC.Admin
{
public class FruitList: System.Web.UI.Page
{
}
}

Q1: When i try to use this.GetType().ToString, it returns
ASP.FruitList_aspx. but I want to get CompanyABC.Admin.FruitList.(When i
watch the object Page in the watch window, I can see
CompanyABC.Admin.FruitList under the [ASP.FruitList_aspx] tree node.) How
can I do that?

Q2: How to truncate CompanyABC so that I can get Admin.FruitList only?
 
Page.GetType().BaseType.ToSTring();
Matt Berther said:
Hello Joel,

You could try this.GetType().Namespace...

--
Matt Berther
http://www.mattberther.com
How can I use Reflection to get full namespace of my web page?

I got a page under this namespace

namespace CompanyABC.Admin
{
public class FruitList: System.Web.UI.Page
{
}
}
Q1: When i try to use this.GetType().ToString, it returns
ASP.FruitList_aspx. but I want to get CompanyABC.Admin.FruitList.(When
i watch the object Page in the watch window, I can see
CompanyABC.Admin.FruitList under the [ASP.FruitList_aspx] tree node.)
How can I do that?

Q2: How to truncate CompanyABC so that I can get Admin.FruitList only?
 
HI Joel

Type t = typeof(FruitList);
t.FullName.ToString();

will you give full name of the class including namespace.

Do remember to include

using System.Reflection;

cheers,

Jerome. M
 
Back
Top