Tuesday, March 27, 2012

List of Pages

Can I programatically get a list of Pages that are part of an ASP.NET
assembly ?"JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
news:%23tzppKFVEHA.2564@.TK2MSFTNGP11.phx.gbl...
> Can I programatically get a list of Pages that are part of an ASP.NET
> assembly ?

You could use Reflection to iterate through all the classes in the assembly
and then look at those which derive from System.Web.UI.Page.
--
John Saunders
johnwsaundersiii at hotmail
"JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
news:%23tzppKFVEHA.2564@.TK2MSFTNGP11.phx.gbl...
> Can I programatically get a list of Pages that are part of an ASP.NET
> assembly ?

You could use Reflection to iterate through all the classes in the assembly
and then look at those which derive from System.Web.UI.Page.
--
John Saunders
johnwsaundersiii at hotmail
I could indeed, good idea. I'll give it a try.

"John Saunders" <johnwsaundersiii@.notcoldmail.com> wrote in message
news:OfB0phIVEHA.2408@.tk2msftngp13.phx.gbl...
> "JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
> news:%23tzppKFVEHA.2564@.TK2MSFTNGP11.phx.gbl...
> > Can I programatically get a list of Pages that are part of an ASP.NET
> > assembly ?
> You could use Reflection to iterate through all the classes in the
assembly
> and then look at those which derive from System.Web.UI.Page.
> --
> John Saunders
> johnwsaundersiii at hotmail
For the record:

private ArrayList GetPages(Assembly a)
{
ArrayList pages = new ArrayList();
foreach (Type tt in a.GetTypes())
{
if (tt.BaseType.Name == "Page")
pages.Add(tt.Name);
}
return pages;
}

"JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
news:OLjB5DRVEHA.2972@.TK2MSFTNGP12.phx.gbl...
> I could indeed, good idea. I'll give it a try.
> "John Saunders" <johnwsaundersiii@.notcoldmail.com> wrote in message
> news:OfB0phIVEHA.2408@.tk2msftngp13.phx.gbl...
> > "JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
> > news:%23tzppKFVEHA.2564@.TK2MSFTNGP11.phx.gbl...
> > > Can I programatically get a list of Pages that are part of an ASP.NET
> > > assembly ?
> > You could use Reflection to iterate through all the classes in the
> assembly
> > and then look at those which derive from System.Web.UI.Page.
> > --
> > John Saunders
> > johnwsaundersiii at hotmail
"JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
news:eNeFMXRVEHA.1656@.TK2MSFTNGP09.phx.gbl...
> For the record:
> private ArrayList GetPages(Assembly a)
> {
> ArrayList pages = new ArrayList();
> foreach (Type tt in a.GetTypes())
> {
> if (tt.BaseType.Name == "Page")
> pages.Add(tt.Name);
> }
> return pages;
> }

I think that tt.IsSubClassOf(typeof(System.Web.UI.Page)) would work better.
Yours will pick up my own type called "Page".
--
John Saunders
johnwsaundersiii at hotmail

> "JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
> news:OLjB5DRVEHA.2972@.TK2MSFTNGP12.phx.gbl...
> > I could indeed, good idea. I'll give it a try.
> > "John Saunders" <johnwsaundersiii@.notcoldmail.com> wrote in message
> > news:OfB0phIVEHA.2408@.tk2msftngp13.phx.gbl...
> > > "JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
> > > news:%23tzppKFVEHA.2564@.TK2MSFTNGP11.phx.gbl...
> > > > Can I programatically get a list of Pages that are part of an
ASP.NET
> > > > assembly ?
> > > > You could use Reflection to iterate through all the classes in the
> > assembly
> > > and then look at those which derive from System.Web.UI.Page.
> > > --
> > > John Saunders
> > > johnwsaundersiii at hotmail
> >
Yes, that's cleaner - thank you.
(IsSubclassOf)

"John Saunders" <johnwsaundersiii@.notcoldmail.com> wrote in message
news:uk$%239HSVEHA.2972@.TK2MSFTNGP12.phx.gbl...
> "JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
> news:eNeFMXRVEHA.1656@.TK2MSFTNGP09.phx.gbl...
> > For the record:
> > private ArrayList GetPages(Assembly a)
> > {
> > ArrayList pages = new ArrayList();
> > foreach (Type tt in a.GetTypes())
> > {
> > if (tt.BaseType.Name == "Page")
> > pages.Add(tt.Name);
> > }
> > return pages;
> > }
> I think that tt.IsSubClassOf(typeof(System.Web.UI.Page)) would work
better.
> Yours will pick up my own type called "Page".
> --
> John Saunders
> johnwsaundersiii at hotmail
>
> > "JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
> > news:OLjB5DRVEHA.2972@.TK2MSFTNGP12.phx.gbl...
> > > I could indeed, good idea. I'll give it a try.
> > > > "John Saunders" <johnwsaundersiii@.notcoldmail.com> wrote in message
> > > news:OfB0phIVEHA.2408@.tk2msftngp13.phx.gbl...
> > > > "JezB" <jezbroadsword@.blueyonder.co.uk> wrote in message
> > > > news:%23tzppKFVEHA.2564@.TK2MSFTNGP11.phx.gbl...
> > > > > Can I programatically get a list of Pages that are part of an
> ASP.NET
> > > > > assembly ?
> > > > > > You could use Reflection to iterate through all the classes in the
> > > assembly
> > > > and then look at those which derive from System.Web.UI.Page.
> > > > --
> > > > John Saunders
> > > > johnwsaundersiii at hotmail
> > > > > >

0 comments:

Post a Comment