




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、在中如何利用模板自動生成靜態(tài)頁面首先是在網(wǎng)站根目錄中建立一個html文件夾,然后建立一個Temp.html文件代碼如下: <!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="
2、Content-Type" content="text/html; charset=gb2312"><title>生成的靜態(tài)頁面</title> 電腦入門<style type="text/css"><!-body background-color: #FFFFFF; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;
3、;font-size:12px;.tabtext color: #FFFFFF-></style></head><body><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="300">logo</td>
4、<td align="right" valign="bottom"> <table width="600" border="0" cellpadding="4" cellspacing="0"> <tr align="center"> <td width="120" bgcolo
5、r="#4279BD" class="tabtext">使用幫助</td> <td width="1"></td> <td width="120" bgcolor="#EFEFEF"><a href="mailto:jusmery" target=&q
6、uot;_blank"> 聯(lián)系我們</a></td> <td width="1"></td> </tr> </table> </td> </
7、tr> <tr bgcolor="#4279BD"> <td height="5" colspan="2"></td> </tr></table><table align="center" width="75%"><tr><td style="text-align:center; background-color:#4279BD;
8、color :White; font-size:26px; line-height:65px;"> $title$</td></tr><tr><td style="color:skyBlue;"> $content$</td></tr></table></body></html> 然后建立Autohtml.aspx<% Page Language=&q
9、uot;C#" AutoEventWireup="true" CodeFile="Autohtml.aspx.cs" Inherits="yamblove_admin_Autohtml" %><!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="ht
10、tp://1999/xhtml"><head runat="server"> <title>自動生成html靜態(tài)頁面</title></head><body> <form id="form1" runat="server"><div> 標題:<asp:Tex
11、tBox ID="txtTitle" runat="server" Width="352px"></asp:TextBox><br /> 內(nèi)容:<asp:TextBox ID="txtContent" runat="server" Height="179px" TextMode="MultiLine" &
12、#160; Width="350px"></asp:TextBox><br /> <br /> <asp:Button ID="SenddataBtn" runat="server" OnClick="sendBtn_Click&
13、quot; Text="提交數(shù)據(jù)模板自動生成html頁面" /><br /> 電腦基礎知識 <br /> <br /> Url地址:<
14、asp:TextBox ID="txtUrl" runat="server" ToolTip="請確認Url地址的存在" Width="359px"></asp:TextBox> <br /> <br /> <asp:B
15、utton ID="Button2" runat="server" Text="根據(jù)Url地址生成html頁面" OnClick="Button2_Click" /> </div> </form></body></html> 其Autohtml.as
16、px.cs 頁面代碼: using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.
17、Xml.Linq;using System.Net;using System.Text;using System.IO;public partial class yamblove_admin_Autohtml : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) protected void sendBtn_Click(object sender, Eve
18、ntArgs e) /源碼是替換掉模板中的特征字符 string mbPath = Server.MapPath("Temp.html"); Encoding code = Encoding.GetEncoding("gb2312");
19、; StreamReader sr = null; StreamWriter sw = null; string str = null; /讀取 try
20、160; sr = new StreamReader(mbPath, code); str = sr.ReadToEnd(); catch (Excep
21、tion ex) throw ex; finally &
22、#160; sr.Close(); /根據(jù)時間自動重命名 string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"
23、60; str = str.Replace("$title$", txtTitle.Text);/替換Title str = str.Replace("$content$", txtContent.Text);/替換content /生成靜態(tài)文件 try
24、60; sw = new StreamWriter(Server.MapPath("html/") + fileName, false, code); sw.Write(str); &
25、#160; sw.Flush(); catch (Exception ex) throw ex;
26、60; finally sw.Close(); Response.Write("恭喜<a href=html/" + fileName + "
27、 target=_blank>" + fileName + "</a>已經(jīng)生成成功,保存在html文件夾下!");計算機基礎知識試題及答案 /根據(jù)Url地址生成靜態(tài)頁保持 protected void Button2_Click(object sender, EventArgs e)
28、; Encoding code = Encoding.GetEncoding("gb2312"); StreamReader sr = null; StreamWriter sw = null; string str = null;
29、 /讀取遠程路徑 WebRequest temp = WebRequest.Create(txtUrl.Text.Trim(); / WebResponse myTemp = temp.GetResponse(); sr = new StreamReader(myTemp.G
30、etResponseStream(), code); /讀取 try sr = new StreamReader(myTemp.GetResponseStream(), code);
31、0; str = sr.ReadToEnd(); catch (Exception ex) throw ex;
32、60; finally sr.Close(); string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司月度室內(nèi)活動方案
- 公司甜品臺活動策劃方案
- 2025年音樂學院入學考試曲目及答案
- 2025年智能制造技術應用考試卷及答案
- 2025年信息系統(tǒng)與工程職業(yè)能力綜合考核試卷及答案
- 2025年社會創(chuàng)業(yè)推動者職業(yè)資格考試試卷及答案
- 2025年室內(nèi)設計師職業(yè)資格考試試卷及答案
- 譯林版(2024)七年級下冊英語期末復習綜合練習試卷(含答案)
- 2025年金融從業(yè)資格證考試題及答案
- 2025年口腔醫(yī)師資格考試題及答案
- 企業(yè)市場營銷策略顧問服務合同范本
- 2024-2025學年人教版 2024小學數(shù)學一年級下冊教學工作總結(jié)(共3套)
- 學生高層宿舍管理制度
- 薪資發(fā)放協(xié)議
- T/CAR 7-2021綠色高效自攜式商用冷藏陳列柜技術要求和評價方法
- 2025-2030年國內(nèi)冷藏集裝箱行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 警務技能抓捕課件
- 廣東省廣州市南沙區(qū)2025屆七下生物期末教學質(zhì)量檢測試題含解析
- DB13T 2700-2018 水工柔性生態(tài)防護結(jié)構設計規(guī)范
- 2025天津中考:語文必背知識點
- 2025汾西礦業(yè)井下操作技能人員招聘300人(山西)筆試參考題庫附帶答案詳解
評論
0/150
提交評論