




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、在中如何利用模板自動生成靜態(tài)頁面首先是在網(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)頁面</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> 標(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ù)模板自動生成html頁面" /><br /> 電腦基礎(chǔ)知識 <br /> <br /> Url地址:<
14、asp:TextBox ID="txtUrl" runat="server" ToolTip="請確認(rèn)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ù)時(shí)間自動重命名 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ǔ)知識試題及答案 /根據(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、 /讀取遠(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 電腦襪機(jī)企業(yè)縣域市場拓展與下沉戰(zhàn)略研究報(bào)告
- 糖糊混合機(jī)企業(yè)ESG實(shí)踐與創(chuàng)新戰(zhàn)略研究報(bào)告
- 電子樂器音質(zhì)提升研究-全面剖析
- 環(huán)境適應(yīng)性材料研究-全面剖析
- 跨文化傳播中的文化挪用現(xiàn)象-全面剖析
- 油果市場供需關(guān)系研究-全面剖析
- 郵件安全風(fēng)險(xiǎn)與防范-全面剖析
- 聯(lián)邦學(xué)習(xí)中的安全多方計(jì)算技術(shù)-全面剖析
- 高純度魚油產(chǎn)品市場發(fā)展趨勢-全面剖析
- 2024年慶陽市華池縣事業(yè)單位選調(diào)工作人員考試真題
- GB/T 4326-2006非本征半導(dǎo)體單晶霍爾遷移率和霍爾系數(shù)測量方法
- 酒水購銷合同范本(3篇)
- GCP培訓(xùn)考試題庫及參考答案(完整版)
- 乒乓球社團(tuán)活動記錄
- 新時(shí)代中小學(xué)教師職業(yè)行為十項(xiàng)準(zhǔn)則考核試題及答案
- 數(shù)據(jù)結(jié)構(gòu)-第6章-圖課件
- 《變態(tài)心理學(xué)與健康心理學(xué)》考試復(fù)習(xí)題庫150題(含答案)
- DB15T 489-2019 石油化學(xué)工業(yè)建設(shè)工程技術(shù)資料管理規(guī)范
- 皮內(nèi)針講課課件
- 村衛(wèi)生室靜脈輸液準(zhǔn)入申請審批表
- 提高鋼柱安裝垂直度合格率QC成果PPT
評論
0/150
提交評論