Asp.net convert asp.net page to page variable

Possible duplicate:
Download an ASP.NET 2.0 aspx page using System.Reflection?

In the following code, I repeat my project and get the file paths for the .aspx pages. How to pass them to a page variable. I tried the following code but did not work. I get the following error message

Invalid cast from 'System.String' to 'System.Web.UI.Page'. 

Please help me.

thanks

 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/>"); Page page = (Page)Convert.ChangeType(filepath, typeof(Page)); } } } 
-3
source share
1 answer

According to your last comment, "I'm trying to go through all the pages of a project and identify the Label and Button controls through each page." Therefore, I think you need the following:

  • Make some base class from which all pages inherit
  • Put some logic in this base class (maybe redefine PreRender, it's not clear what you want to do with the controls) and find all the controls (Label and Button) on these pages (you probably need to implement your own FindControl method, because FindControl in ASP.NET is not recursive ).

This is much better and cleaner than what you are trying to achieve when downloading .aspx directly, etc.

+1
source

All Articles