Possible Duplicate:
Load an ASP.NET 2.0 aspx page using System.Reflection?
In the following code, I iterate through my project and get file paths for .aspx pages. How do cast them to Page variable. I have tried the following code but its not working. 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));
}
}
}