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); }
Project
->
Show all files
white color
Include in Project
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)