Click here to Skip to main content
15,921,062 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi. i try to create an asp page (for example:"ok.aspx" & "ok.aspx.cs") programatically. and i use this code. but the problem is just "ok.aspx" is created. what is the problem?

C#
string rndFileName = string.Format(@"{0}", Guid.NewGuid();
            string[] aspxLines =
            {
                "<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\""+rndFileName+".aspx.cs\" Inherits=\"PRJs."+rndFileName+"\" %> <!DOCTYPE html><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>"
            };
            string[] cslines =
            {
                "using System;",
                "using System.Collections.Generic;",
                "using System.Linq;",
                "using System.Web;",
                "using System.Web.UI;",
                "using System.Web.UI.WebControls;",
               " namespace PRJs",
               " {",
                   " public partial class "+ rndFileName+" : System.Web.UI.Page",
                   " {",
                       " protected void Page_Load(object sender, EventArgs e)",
                       " {",
                       "Response.Write(\"Hi\");",
                     "   }",
                    "}",
               " }"
            };

            File.WriteAllLines(Server.MapPath(rndFileName + ".aspx"), aspxLines);
            File.WriteAllLines(Server.MapPath(rndFileName + ".aspx.cs"), cslines);     
Posted
Comments
Prasad Khandekar 28-Apr-13 8:31am    
Have you tried with a hardcode name?

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