asp.net convert asp.net page into Page variable
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/376404/load-an-asp-net-2-0-aspx-page-using-system-reflection">Load an ASP.NET 2.0 aspx page using System.Reflection?</a>  </p>
</blockquote>



<p>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</p>

<pre><code>Invalid cast from 'System.String' to 'System.Web.UI.Page'.
</code></pre>

<p>Please help me.</p>

<p>thanks</p>

<pre><code>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 + "&lt;br/&gt;");

            Page page = (Page)Convert.ChangeType(filepath, typeof(Page));

        }
    }


}
</code></pre>
