Click here to Skip to main content
15,917,565 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?

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=\"\">",
                "<head runat=\"server\"><title></title>",
                        "<form id=\"form1\" runat=\"server\">",
                   " </body>",
            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)",
                       " {",
                     "   }",
               " }"

            File.WriteAllLines(Server.MapPath(rndFileName + ".aspx"), aspxLines);
            File.WriteAllLines(Server.MapPath(rndFileName + ".aspx.cs"), cslines);     
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