怎样生成静态页 如题 求一简单的例子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面的示例可能对楼主有帮助; 这是CreateHtml.aspx文件代码: <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Text" %> <script runat="server" language="vb"> '该过程用来生成HTML网页 Sub Enter_Click(Sender As System.Object, E As System.EventArgs) '下面首先读取模板文件,将其中的全部代码保存到一个字符串中 Dim strTemplate As String Dim sr As New StreamReader(Server.MapPath("template.htm"), Encoding.GetEncoding("gb2312")) strTemplate=sr.ReadToEnd() sr.Close() '下面利用客户输入的内容替换模板中的相应字符串 strTemplate=strTemplate.Replace("$title$",txtTitle.Text) strTemplate=strTemplate.Replace("$body$",txtBody.Text) strTemplate=strTemplate.Replace("$SubmitDate$",Now()) '下面建立一个StreamWriter对象,生成HTML文件 Dim sw As New StreamWriter(Server.MapPath(GetFileName()), False, Encoding.GetEncoding("gb2312")) sw.Write(strTemplate) sw.Close() '下面给出一个浏览超链接 message.Text = "<a href='" & GetFileName() & "' target='_blank'>请查看生成的文件</a>" End Sub '该函数用来返回由当前时间组成的文件名称 Function GetFileName() GetFileName = Now().ToString.Replace("-","").Replace(":","").Replace(" ","") GetFileName = GetFileName & ".htm" End Function </script> <HTML> <body> <h3 align="center">利用模板生成HTML文件</h3> <form runat="server"> <table width="80%" align="center"> <tr> <td width="30%" align="right">标题</td> <td><asp:Textbox id="txtTitle" columns="50" runat="server"/></td> </tr> <tr> <td width="30%" align="right">内容</td> <td><asp:Textbox id="txtBody" TextMode="MultiLine" rows="8" columns="40" runat="server"/></td> </tr> <tr> <td colspan="2" align="center"><asp:Button id="Enter" Text="确定" Runat="server" OnClick="Enter_Click"/></td> </tr> </table> <asp:Label id="message" Runat="server" /> </form> </BODY> </HTML> 这是模版文件代码template.htm: <html> <head> <title>$title$</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <h3 align="center">$title$</h3> <table height="80%" border="0" width="100%" cellpadding="10" cellspacing="0" bgcolor="#eeeeee" style="border:1px solid #000000"> <tr valign="top"> <td>$body$</td> </tr> </table> <p align="center">信息中心 $SubmitDate$</p> </body> </html> 我的做法是读取页面将返回的HTML保存为静态页面 http://www.google.com.hk/search?hl=zh-CN&source=hp&q=asp.net%E7%94%9F%E6%88%90%E9%9D%99%E6%80%81%E9%A1%B5%E9%9D%A2&aq=0g&aqi=g-g1&aql=&oq=asp.net+%E7%94%9F%E6%88%90%E9%9D%99%E6%80%81%E9%A1%B5&gs_rfai= 参考这个:http://topic.csdn.net/u/20090110/21/fca6d5e2-f02c-4d9c-8657-d7a3dd11da88.html 如果你要对网页 abc.aspx进行静态,得到abc.htmlServer.Execute("abc.aspx", new StreamWriter(Server.MapPath("abc.html"))); urlrewriter伪静态模板public static bool WriteFile(string strText) { string path = HttpContext.Current.Server.MapPath("Html/"); System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312"); string temp = HttpContext.Current.Server.MapPath("Html/A.html"); StreamReader sr = null; StreamWriter sw = null; string str = ""; try { sr = new StreamReader(temp, code); str = sr.ReadToEnd(); } catch (Exception exp) { HttpContext.Current.Response.Write(exp.Message); HttpContext.Current.Response.End(); sr.Close(); } string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"; //通过正则获取标签内容实现内容替换 try { sw = new StreamWriter(path + htmlfilename, false, code); sw.Write(str); sw.Flush(); } catch (Exception ex) { HttpContext.Current.Response.Write(ex.Message); HttpContext.Current.Response.End(); } finally { sw.Close(); } return true; } StringWriter wr = new StringWriter();Server.Execute("", wr); File.WriteAllText(Server.MapPath(""), wr.ToString()); 将aspx页面导出成word文档 郁闷 发发牢骚 刚刚跟技术总监吵了一架 不知道是对是错。。 新人求帮助~ 怎样让验证控件失效? 怎样取消验证控件的验证功能?????(加急 在线等) 悬而未决的问题。 求大神。求思路。网页视频,类似于QQ视频聊天,应用到网页中。 请问一个DetailsView和DropDownList的问题: 在不装VS。NET下运行程序后的错误,是什么原因啊? 我要打印一个查询的数据表,有几百条,怎么办 重发:缺少using引用(非小白问题) SQL分组求解决方案
下面的示例可能对楼主有帮助;
这是CreateHtml.aspx文件代码:
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<script runat="server" language="vb">
'该过程用来生成HTML网页
Sub Enter_Click(Sender As System.Object, E As System.EventArgs)
'下面首先读取模板文件,将其中的全部代码保存到一个字符串中
Dim strTemplate As String
Dim sr As New StreamReader(Server.MapPath("template.htm"), Encoding.GetEncoding("gb2312"))
strTemplate=sr.ReadToEnd()
sr.Close()
'下面利用客户输入的内容替换模板中的相应字符串
strTemplate=strTemplate.Replace("$title$",txtTitle.Text)
strTemplate=strTemplate.Replace("$body$",txtBody.Text)
strTemplate=strTemplate.Replace("$SubmitDate$",Now())
'下面建立一个StreamWriter对象,生成HTML文件
Dim sw As New StreamWriter(Server.MapPath(GetFileName()), False, Encoding.GetEncoding("gb2312"))
sw.Write(strTemplate)
sw.Close()
'下面给出一个浏览超链接
message.Text = "<a href='" & GetFileName() & "' target='_blank'>请查看生成的文件</a>"
End Sub
'该函数用来返回由当前时间组成的文件名称
Function GetFileName()
GetFileName = Now().ToString.Replace("-","").Replace(":","").Replace(" ","")
GetFileName = GetFileName & ".htm"
End Function
</script>
<HTML>
<body>
<h3 align="center">利用模板生成HTML文件</h3>
<form runat="server">
<table width="80%" align="center">
<tr>
<td width="30%" align="right">标题</td>
<td><asp:Textbox id="txtTitle" columns="50" runat="server"/></td>
</tr>
<tr>
<td width="30%" align="right">内容</td>
<td><asp:Textbox id="txtBody" TextMode="MultiLine" rows="8" columns="40" runat="server"/></td>
</tr>
<tr>
<td colspan="2" align="center"><asp:Button id="Enter" Text="确定" Runat="server" OnClick="Enter_Click"/></td>
</tr>
</table>
<asp:Label id="message" Runat="server" />
</form>
</BODY>
</HTML>
这是模版文件代码template.htm:
<html>
<head>
<title>$title$</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h3 align="center">$title$</h3>
<table height="80%" border="0" width="100%" cellpadding="10" cellspacing="0" bgcolor="#eeeeee"
style="border:1px solid #000000">
<tr valign="top">
<td>$body$</td>
</tr>
</table>
<p align="center">信息中心 $SubmitDate$</p>
</body>
</html>
http://topic.csdn.net/u/20090110/21/fca6d5e2-f02c-4d9c-8657-d7a3dd11da88.html
模板
public static bool WriteFile(string strText)
{
string path = HttpContext.Current.Server.MapPath("Html/");
System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");
string temp = HttpContext.Current.Server.MapPath("Html/A.html");
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd();
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
//通过正则获取标签内容实现内容替换
try
{
sw = new StreamWriter(path + htmlfilename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
return true;
}
StringWriter wr = new StringWriter();
Server.Execute("", wr);
File.WriteAllText(Server.MapPath(""), wr.ToString());