I am trying one more time to reach out to asp.net experts and hoping to get an answer. I am really stuck here and asking for help. Hopefully, my question will not get down voted, and I could get an answer purely from technical point of view instead of people simply being judgmental on my approach.
Earlier I posted question as follows: asp.net convert asp.net page into Page variable
Then I looked at following page but still its not working for me.
Load an ASP.NET 2.0 aspx page using System.Reflection?
Inside my web application, I would like to be able to reference web pages any where in my code like "WebForm1.aspx" and get a listing of the controls on that page. Please just look at it from this point of view and not over analyze it. Is it possible?
In my Page variable p, I do not seem to have any controls for WebForm1.aspx
Here is my code.
Please help.
protected void Page_Load(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(Server.MapPath("~/"), "*.*", SearchOption.AllDirectories);
foreach (string filepath in filePaths)
{
if (filepath.EndsWith(".aspx"))
{
Response.Write(filepath + "<br/>");
string[] folders = filepath.Split('\\');
string filename = folders[folders.Count() - 1];
string fullpath = "~/" + filename;
Page p = BuildManager.CreateInstanceFromVirtualPath("~/"+fullpath, typeof(Page)) as Page;
List<String> controlList = new List<String>();
ResourceManager.AddControls(p.Controls, controlList);
foreach (string str in controlList)
{
Response.Write(str + "<br/>");
}
}
}