生成静态页
运行测试,显示 无法显示网页
代码如下
protected override void Render(HtmlTextWriter writer)
{
string filename = ""
+ DateTime.Now.Year
+ DateTime.Now.Month
+ DateTime.Now.Day
+ DateTime.Now.Hour
+ DateTime.Now.Minute
+ DateTime.Now.Second
+ DateTime.Now.Millisecond + ".htm";
try
{
string newpath = Server.MapPath(".") + "\\" + filename;
//string newpath = Server.MapPath("newfile") + "\\" + filename;
FileStream fs = File.Create(newpath);
fs.Close();
//File.Create(Server.MapPath("newfile") + "\\" + filename);
StreamWriter r = new StreamWriter(newpath, false, System.Text.Encoding.UTF8);
HtmlTextWriter h = new HtmlTextWriter(r);
base.Render(h);
Response.Redirect(newpath);
r.Close();
h.Close();
}
catch (Exception error)
{
throw error;
}
}
谢谢。
string newpath = Server.MapPath(".") + "\\" + filename;
改成
string newpath = Server.MapPath(filename) ;
可以参考我的静态页生成
http://www.cnblogs.com/goldencode/archive/2010/12/09/aspx_To_Html.html
你的newpath用server.mappath处理过了,应该是服务器上的文件路径了.
或者这样试试:
string newpath = filename;
FileStream fs = File.Create(Server.MapPath(filename));
另外用当前时间做文件名不用这么麻烦,直接DateTime.Now.ToString("yyyyMMddHHmmssfff")就可以了.