简体   繁体   中英

How to add new items in our project dynamically from our program?

Is there is any method to add new items or existing items in our project from our program?

For example: if i need to add example.aspx page from my program then how to add it?? And it should save in solution explorer.

normally you would use a CMS-alike workflow, where you can set up a Master Layout and then make an Administrative way to add content to each part of the page you would want.

In a simple way, you can just easily create pages using 2 textboxes and a submit button:

<input type="text" id="txtFileName" />
<textarea id="txtContent" rows="80" cols="12"></textarea>
<input type="submit" id="btnSave" value="Save File" />

and have your code to create a new text file with the passed contents like:

// create a writer and open the file
using (TextWriter tw = new StreamWriter(
                                 txtFileName.Text, 
                                 false, 
                                 System.Text.Encoding.UTF8))
{
    // write the content
    tw.Write(txtContent.Text);

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

You can show a list of all files and read them the same way, so you can edit them...

Now , in ASP.NET, this might not work properly as the server will need to compile again and for that you will need to also change the project file, but you can run a local script issuing the compile line and that will re-compile everything for you.

Give it a try, and when you come up with some stopper, let us know, we might give you a hand on that...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM