tags:

views:

101

answers:

4

Hi

I want to create a Dynamic aspx Page in current solution through code-behind..forexample i have a 2 text-boxes one for page-Title another another for page-Content and a button.. whenever that button is pressed, An aspx Page should be created in current solution and should be included in the current solution.

need help...

A: 

Have you considered using a visual studio macro to accomplish this? I odn't have any examples I can share but have written tons that generate stuff and add to your project. It's a bit of a pain the 1st time but once you have it it's easily extendible. Maybe T4 has something that can help you?

No Refunds No Returns
A: 

If you're using a "Web Site project" (not a web application project), then this should be easy, because this project type does not have a project file and all files which exist below the web site's root folder are automatically part of the solution.

So you can simply create an ASPX file and store it below your application's root folder, e.g. something like this (very simplified):

var content = "<%@ Page Language=\"C#\" %><html><head runat=\"server\"><title>"
  + txtTitle.Text
  + "</title></head><body><form id=\"form1\" runat=\"server\">"
  + txtContent.Text
  + "</form></body></html>";

System.IO.File.WriteAllText(Server.MapPath("~/newfile.aspx", content));
M4N
Of course, if the project is open when this is executed then it will need to be manually refreshed to show the new file. It's unclear whether or not this would work for the OP's needs or not...
Seth Petry-Johnson
@Martin thnx, but m using Web Application project
Pranali Desai
A: 

What exactly are you trying to accomplish? I'm having a hard time understanding when this would be useful.

If you're trying to simplify file creation during development, then you should probably not be using a web page as your tool. You should consider a VS macro or template or some other IDE-focused process.

If you want end users to create new content, you might consider using a pre-existing Content Management Solution or storing content in the database and retrieving it via a single dynamic page (e.g. Content.aspx or something). This way you don't have to worry about users creating filenames with invalid names, or duplicate files, or anything like that.

Is there a particular reason you want to use a web page to modify your project files?

Seth Petry-Johnson
@Seth, you are right i can use CMS, but my WebApplication the one m thinkin' to build is some what work like CMS for Page/Content Adding.
Pranali Desai
@Seth,But I can't use CMS coz, Maintin' Content is a small part in my Application.
Pranali Desai
@Pranali Desai, you can build a really small 'content management system' which deals with the two parameters title and maincontent like i said in the comments before :)
JP Hellemons
A: 

You really need a Content Management System. It's as simple as that. Use the proper tool for the job, my friend. There are plenty of free and open source options. Look into them.

Bryan