tags:

views:

16

answers:

1

Hi,

I'm developing a website that has modular section. I would like it that when a new aspx (and aspx.cs) file is placed in a subdirectory of the application that I can ask the class some information...

The idea is that when the file is placed in the directory a new menu item is added to the menu. To do that I need to "ask the class" for its name, icon, description, etc.

Is there a way to determine the class that is defined in codebehind file and to instantiate an instance of it?

I know I could look for and parse a config file for each plugin but I would rather not have to go that route.

+3  A: 

The "standard" method for this is the config file you mention, in the form of a Sitemap. You'll get a lot of good features out of it by doing it that way, like breadcrumbs and so forth. I know this is exactly the answer you asked not to get, but there it is anyway.

If you insist, though, there's nothing stopping you from using MapPath and actually searching the disk for .aspx files, parsing them to pull out certain info (like class name), and then doing whatever you like.

But SiteMap is better, unless you have some very strange requirement. Note that your sitemap can come from a database or another dynamic source, it doesn't have to be an XML file.

Scott Stafford
You'll also get a bit better security, as you don't have to allow random people to put random .aspx files in a folder and have them suddenly appear and do whatever the author wanted them to do.
John Saunders