如何生成使用asp.net在服务器上的一个新的html页面? [英] How to generate a new html page on the server using asp.net?
问题描述
我希望让这个由pressing主页上的一个按钮,用户将能够在网站的服务器上创建一个新的HTML页面(如www.example.com/0002.html)我需要这个页面大家要永远存在和访问。如何才能可编程创建一个HTML页面使用asp.net?
I want to make it so that by pressing a button on the homepage a user will be able to create a new html page on the server of the website (e.g. www.example.com/0002.html) I need this page to be always there and accessible by everyone. How can one create a html page programmably using asp.net?
推荐答案
要在服务器上创建一个文件,你的服务器端code将需要使用一个FileStream写入磁盘,就像你写磁盘在一个正常的桌面应用程序。有一件事你需要做的就是把它写它保存你的网站目录内。
To create a file on the server, your server side code would need to use a FileStream to write to the disk, just like you would write to the disk in a normal desktop application. The one thing you would need to do is write it inside of the directory which holds your site.
有些code编写一个文件:
Some code to write a file:
using (StreamWriter sw = new StreamWriter(Server.MapPath("fileName.html")))
using (HtmlTextWriter writer = new HtmlTextWriter(sw))
{
writer.RenderBeginTag(HtmlTextWriterTag.Html);
writer.RenderBeginTag(HtmlTextWriterTag.Head);
writer.Write("Head Contents");
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Body);
writer.Write("Body Contents");
writer.RenderEndTag();
writer.RenderEndTag();
}
这篇关于如何生成使用asp.net在服务器上的一个新的html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!