




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、在中如何利用模板自動(dòng)生成靜態(tài)頁(yè)面首先是在網(wǎng)站根目錄中建立一個(gè)html文件夾,然后建立一個(gè)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)頁(yè)面</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>自動(dòng)生成html靜態(tài)頁(yè)面</title></head><body> <form id="form1" runat="server"><div> 標(biāo)題:<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ù)模板自動(dòng)生成html頁(yè)面" /><br /> 電腦基礎(chǔ)知識(shí) <br /> <br /> Url地址:<
14、asp:TextBox ID="txtUrl" runat="server" ToolTip="請(qǐng)確認(rèn)Url地址的存在" Width="359px"></asp:TextBox> <br /> <br /> <asp:B
15、utton ID="Button2" runat="server" Text="根據(jù)Url地址生成html頁(yè)面" OnClick="Button2_Click" /> </div> </form></body></html> 其Autohtml.as
16、px.cs 頁(yè)面代碼: 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ù)時(shí)間自動(dòng)重命名 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ì)算機(jī)基礎(chǔ)知識(shí)試題及答案 /根據(jù)Url地址生成靜態(tài)頁(yè)保持 protected void Button2_Click(object sender, EventArgs e)
28、; Encoding code = Encoding.GetEncoding("gb2312"); StreamReader sr = null; StreamWriter sw = null; string str = null;
29、 /讀取遠(yuǎn)程路徑 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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 關(guān)于扶持政策的潛在風(fēng)險(xiǎn)研究試題及答案
- 商務(wù)信息傳播的英語(yǔ)試題及答案
- 器樂(lè)樂(lè)理考試考點(diǎn)試題及答案
- 家具設(shè)計(jì)中的裝置藝術(shù)與商業(yè)價(jià)值研究試題及答案
- 團(tuán)隊(duì)協(xié)作面試題及答案
- 廣州高一試題及答案
- 創(chuàng)業(yè)扶持政策的歷史發(fā)展與未來(lái)展望試題及答案
- 智能駕駛的技術(shù)實(shí)現(xiàn)路徑考核試題及答案
- 新能源汽車產(chǎn)品生命周期管理試題及答案
- 如何利用新媒體提高農(nóng)產(chǎn)品市場(chǎng)滲透率試題及答案
- 新版院感培訓(xùn)課件
- 2024-2025學(xué)年上海市浦東新區(qū)初三一模語(yǔ)文試卷(含答案)
- 企業(yè)創(chuàng)新韌性的驅(qū)動(dòng)路徑研究
- 2025年江蘇泰州市第四人民醫(yī)院招聘高層次人才15人歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 二零二五年度跨境電商合伙人合作協(xié)議書3篇
- 知憲明法與憲同行課件-高一上學(xué)期憲法宣傳周主題班會(huì)
- 《高速公路電動(dòng)汽車清障救援作業(yè)規(guī)范》
- UL489標(biāo)準(zhǔn)中文版-2019斷路器UL標(biāo)準(zhǔn)中文版
- 【MOOC】建筑結(jié)構(gòu)概論-河南理工大學(xué) 中國(guó)大學(xué)慕課MOOC答案
- DB21-T 1642-2024 鎂質(zhì)耐火原料及制品單位產(chǎn)品能源消耗限額
- 維修電工二實(shí)操評(píng)分表講解
評(píng)論
0/150
提交評(píng)論