Click here to Skip to main content
16,020,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am creating asp.net page dynamically and it is creating very well but the problem is not showing in solution explorer.

here is my code to create dynamic page...

XML
try
            {
                fielName = Server.MapPath("~/Sample.aspx");
                ViewState["Createdpage"] = fielName.ToString();
                //File.Create(fielName);
                //File.AppendText(fielName);


                // create a writer and open the file
                TextWriter tw = new StreamWriter(fielName);

                // write a line of text to the file
                tw.WriteLine(@"<%@ Page Language=""C#"" AutoEventWireup=""true""  CodeFile=""Sample.aspx.cs"" Inherits=""DynamicPages.Sample"" %>

<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">

<html xmlns=""http://www.w3.org/1999/xhtml"">
<head runat=""server"">
    <title></title>
</head>
<body>
    <form id=""form1"" runat=""server"">
    <div>

    </div>
    </form>
</body>
</html>
");

                // close the stream
                tw.Close();


                tw = new StreamWriter(fielName + ".cs");


                // write a line of text to the file
                tw.WriteLine(@"using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace DynamicPages
{
    public partial class Sample : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {


    }
}
}");
                // close the stream
                tw.Close();

                tw = new StreamWriter(fielName + ".designer.cs"); //Default.aspx.designer.cs

                tw.WriteLine(@"namespace DynamicPages {


    public partial class Sample {

        /// <summary>
        /// form1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.HtmlControls.HtmlForm form1;

        /// <summary>
        /// btnAdd control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Button btnAdd;
    }
}");

                // close the stream
                tw.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
Posted
Updated 28-Sep-12 0:25am
v2
Comments
Ashraff Ali Wahab 28-Sep-12 16:36pm    
Page is created but not added to project yet,so it will not show in the solution explorer.You can select the icon to show all files in the solution explore to see the file.
Parshu2378 1-Oct-12 1:49am    
but i need to do it at run time with programmatically.

As Ashraff said you need to turn on the icon to see all files because it is on the drive but not added to the project.
 
Share this answer
 
Click on Project in Solution explorer -> Click Show all files on the menu bar above the Solution File -> Now the file will be displayed in white color -> Right Click on that File and click Include in Project
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900