473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

find ASPX and ASCX pages in a web project..

hi there,

Can someone help me out with some example code (VB.NET) here that i need:

i would like to programatically check my ASP.NET web application and return
a list of all the ASPX and ASCX pages in the project, then return them in an
string array, eg. name : type ("default.aspx : ASPX")

i figured if i use the io.directory, it might even return items which could
be excluded from the project, which i dont want, thats why i think it might
be best to use the assembly??

thanks,

Paul.
Nov 18 '05 #1
4 1641
You can come pretty close by using reflection.
The following snippet creates an ArrayList with the class
name and type of all pages and user controls within the
assembly:
Type[]
allTypes=Assembly.GetExecutingAssembly().GetTypes( );
ArrayList
pagesAndUserControls=new ArrayList();
foreach (Type type in allTypes) {
if (type.IsSubclassOf
(typeof(System.Web.UI.Page))||type.IsSubclassOf(ty peof
(System.Web.UI.UserControl))) {

pagesAndUserControls.Add(String.Format("{0} :
{1}",type.FullName,type.BaseType));
}
}

You will need to add the following using statement to the
class "using System.Reflection;"

Usually you give the code behind class the same name as
the aspx or ascx page. Eg. WebForm1.aspx has a class
named WebForm1. If you follow this patter you can
append ".aspx" or ".ascx" to the class names to get the
filename of the page or control.

Regards,
Anders Norås - blog:
http://dotnetjunkies.com/weblog/anoras
-----Original Message-----
hi there,

Can someone help me out with some example code (VB.NET) here that i need:
i would like to programatically check my ASP.NET web application and returna list of all the ASPX and ASCX pages in the project, then return them in anstring array, eg. name : type ("default.aspx : ASPX")

i figured if i use the io.directory, it might even return items which couldbe excluded from the project, which i dont want, thats why i think it mightbe best to use the assembly??

thanks,

Paul.
.

Nov 18 '05 #2
Hello Anders,

One step is missing from your otherwise great instructions:

You're assuming that there is only one assembly containing the AS?X files
and that it is the currently executing one. It is very probable that a user
may have multiple assemblies in the bin directory (this is a practice I do
frequently).

To get around that, you'll need to add a loop to iterate the assemblies:

foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
// your code goes here
}

After that, you'll want to modify your allTypes assignment this way:

Type[] allTypes = asm.GetTypes();

--
Matt Berther
http://www.mattberther.com
You can come pretty close by using reflection.The following snippet
creates an ArrayList with the class name and type of all pages and
user controls within the assembly: Type[]
allTypes=Assembly.GetExecutingAssembly().GetTypes( ); ArrayList
pagesAndUserControls=new ArrayList(); foreach (Type type in
allTypes) { if (type.IsSubclassOf
(typeof(System.Web.UI.Page))||type.IsSubclassOf(ty peof
(System.Web.UI.UserControl))) {
pagesAndUserControls.Add(String.Format("{0} :
{1}",type.FullName,type.BaseType)); } }You will need to add
the following using statement to the class "using System.Reflection;"
Usually you give the code behind class the same name as the aspx or
ascx page. Eg. WebForm1.aspx has a class named WebForm1. If you
follow this patter you can append ".aspx" or ".ascx" to the class
names to get the filename of the page or control.Regards,Anders
Norås - blog: http://dotnetjunkies.com/weblog/anoras>-----Original
Message----->hi there,>>Can someone help me out with some example
code (VB.NET) here that i need:>>i would like to programatically
check my ASP.NET web application and return>a list of all the ASPX
and ASCX pages in the project, then return them in an>string array,
eg. name : type ("default.aspx : ASPX")>>i figured if i use the
io.directory, it might even return items which could>be excluded
from the project, which i dont want, thats why i think it might>be
best to use the assembly??>>thanks,>>Paul.>>>.>

Nov 18 '05 #3
great!! thanks for the excellent example.. i had a fair idea what i was
after, but just didnt know exactly where to start code-wise.

just one small issue, i've converted the code into VB.NET, but one line is
giving me a problem:

If t.IsSubclassOf(typeOf(System.Web.UI.Page)) Or
t.IsSubclassOf(typeof(System.Web.UI.UserControl)) Then
it doesnt like this line of code how i have written it,any help?

thanks,
Paul

"Matt Berther" <mb******@hotmail.com> wrote in message
news:61***********************@news.microsoft.com. ..
Hello Anders,

One step is missing from your otherwise great instructions:

You're assuming that there is only one assembly containing the AS?X files
and that it is the currently executing one. It is very probable that a user may have multiple assemblies in the bin directory (this is a practice I do
frequently).

To get around that, you'll need to add a loop to iterate the assemblies:

foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
// your code goes here
}

After that, you'll want to modify your allTypes assignment this way:

Type[] allTypes = asm.GetTypes();

--
Matt Berther
http://www.mattberther.com
You can come pretty close by using reflection.The following snippet
creates an ArrayList with the class name and type of all pages and
user controls within the assembly: Type[]
allTypes=Assembly.GetExecutingAssembly().GetTypes( ); ArrayList
pagesAndUserControls=new ArrayList(); foreach (Type type in
allTypes) { if (type.IsSubclassOf
(typeof(System.Web.UI.Page))||type.IsSubclassOf(ty peof
(System.Web.UI.UserControl))) {
pagesAndUserControls.Add(String.Format("{0} :
{1}",type.FullName,type.BaseType)); } }You will need to add
the following using statement to the class "using System.Reflection;"
Usually you give the code behind class the same name as the aspx or
ascx page. Eg. WebForm1.aspx has a class named WebForm1. If you
follow this patter you can append ".aspx" or ".ascx" to the class
names to get the filename of the page or control.Regards,Anders
Norås - blog: http://dotnetjunkies.com/weblog/anoras>-----Original
Message----->hi there,>>Can someone help me out with some example
code (VB.NET) here that i need:>>i would like to programatically
check my ASP.NET web application and return>a list of all the ASPX
and ASCX pages in the project, then return them in an>string array,
eg. name : type ("default.aspx : ASPX")>>i figured if i use the
io.directory, it might even return items which could>be excluded
from the project, which i dont want, thats why i think it might>be
best to use the assembly??>>thanks,>>Paul.>>>.>


Nov 18 '05 #4
I'm think the VB.NET equivalent to typeof is GetType but I'm not sure.
BTW: I've got an updated example on how to do this posted on my blog.

Regards,
Anders Norås
blog: http://dotnetjunkies.com/weblog/anoras

"Milsnips" <mi******@hotmail.com> wrote in message
news:uv*************@TK2MSFTNGP14.phx.gbl...
great!! thanks for the excellent example.. i had a fair idea what i was
after, but just didnt know exactly where to start code-wise.

just one small issue, i've converted the code into VB.NET, but one line is
giving me a problem:

If t.IsSubclassOf(typeOf(System.Web.UI.Page)) Or
t.IsSubclassOf(typeof(System.Web.UI.UserControl)) Then
it doesnt like this line of code how i have written it,any help?

thanks,
Paul

"Matt Berther" <mb******@hotmail.com> wrote in message
news:61***********************@news.microsoft.com. ..
Hello Anders,

One step is missing from your otherwise great instructions:

You're assuming that there is only one assembly containing the AS?X files
and that it is the currently executing one. It is very probable that a

user
may have multiple assemblies in the bin directory (this is a practice I
do
frequently).

To get around that, you'll need to add a loop to iterate the assemblies:

foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
// your code goes here
}

After that, you'll want to modify your allTypes assignment this way:

Type[] allTypes = asm.GetTypes();

--
Matt Berther
http://www.mattberther.com
> You can come pretty close by using reflection.The following snippet
> creates an ArrayList with the class name and type of all pages and
> user controls within the assembly: Type[]
> allTypes=Assembly.GetExecutingAssembly().GetTypes( ); ArrayList
> pagesAndUserControls=new ArrayList(); foreach (Type type in
> allTypes) { if (type.IsSubclassOf
> (typeof(System.Web.UI.Page))||type.IsSubclassOf(ty peof
> (System.Web.UI.UserControl))) {
> pagesAndUserControls.Add(String.Format("{0} :
> {1}",type.FullName,type.BaseType)); } }You will need to add
> the following using statement to the class "using System.Reflection;"
> Usually you give the code behind class the same name as the aspx or
> ascx page. Eg. WebForm1.aspx has a class named WebForm1. If you
> follow this patter you can append ".aspx" or ".ascx" to the class
> names to get the filename of the page or control.Regards,Anders
> Norås - blog: http://dotnetjunkies.com/weblog/anoras>-----Original
> Message----->hi there,>>Can someone help me out with some example
> code (VB.NET) here that i need:>>i would like to programatically
> check my ASP.NET web application and return>a list of all the ASPX
> and ASCX pages in the project, then return them in an>string array,
> eg. name : type ("default.aspx : ASPX")>>i figured if i use the
> io.directory, it might even return items which could>be excluded
> from the project, which i dont want, thats why i think it might>be
> best to use the assembly??>>thanks,>>Paul.>>>.>
>



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Fabrizio Maltese | last post by:
Hi, I created a project with a page in aspx. How can I put the page in my WebSite, that is not on my server? Do i need a setup project that goes on the Web Server? Thank you, Fabrizio
4
by: BH | last post by:
I'm looking at the source code of the ASP.NET forum sample application. It has the "code-behind" classes compiled into a separate DLL, totally separated from the aspx/ascx files. Adding the class...
3
by: Tom | last post by:
Hi, I have an index.aspx page which includes top.aspx, left.aspx, main.aspx and bottom.aspx. In the left.aspx, there is a login web control - login.ascx. It keeps session of username and role...
2
by: Peter Jackson | last post by:
I'm using v2 of the UIP App. Block. I've created all my .aspx pages, all of which contain .ascx user controls. The .ascx user controls provide the standard server controls (i.e., LinkButtons, etc.)...
4
by: Vladimír Kolesnik | last post by:
Hi there, does anybody know, how to create a class, which is can be inherited by both aspx (System.Web.UI.Page) as well as by ascx (System.Web.UI.UserControl) classes. I have the bunch of same...
4
by: Milsnips | last post by:
Can anyone help out on this one? i would like to find out all the ASPX and ASCX pages that are in my project, and return them in an arraylist. thanks, Paul.
6
by: Martin Eyles | last post by:
Hi, I have a .aspx page which has a .ascx file included through the lines <%@ Register TagPrefix="aspcustom" TagName="menu" Src="Menu.ascx" %> and <aspcustom:menu id="Menu1"...
2
by: tbh | last post by:
hi, hope this cross-post is OK. it's unclear to me whether this question belongs more under vstudio or dotnet... i'm using VS2005 pro and am one co-developer of a web solution that is getting to...
2
by: Max2006 | last post by:
Hi, Is there any way to break a web application into separated web projects, so we can re-use pages\? I am trying to put aspx pages and/or ascx pages in separated web projects,
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.