免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
asp.net生成靜態(tài)頁的兩種方法

Default.aspx頁面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication6._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Asp.net生成靜態(tài)頁的兩個(gè)例子</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        標(biāo)題:<asp:TextBox ID="txtTitle" runat="server" Width="352px"></asp:TextBox><br />
        內(nèi)容:<asp:TextBox ID="txtContent" runat="server" Height="179px" TextMode="MultiLine"
            Width="350px"></asp:TextBox><br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="根據(jù)模板生成" /><br />
        <br />
        <br />
        Url地址:<asp:TextBox ID="txtUrl" runat="server" ToolTip="請(qǐng)確認(rèn)Url地址的存在" Width="359px"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button2" runat="server" Text="根據(jù)Url地址生成" OnClick="Button2_Click" /></div>
    </form>
</body>
</html>

 

Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;
using System.IO;

namespace WebApplication6
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //源碼是替換掉模板中的特征字符

            string mbPath = Server.MapPath("template.htm");
            Encoding code = Encoding.GetEncoding("gb2312");
            StreamReader sr = null;
            StreamWriter sw = null;
            string str = null;

            //讀取
            try
            {
                sr = new StreamReader(mbPath, code);
                str = sr.ReadToEnd();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sr.Close();
            }
            //根據(jù)時(shí)間自動(dòng)重命名,擴(kuò)展名也可以自行修改
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm";
            str = str.Replace("$title$", txtTitle.Text);//替換Title
            str = str.Replace("$content$", txtContent.Text);//替換content
            //生成靜態(tài)文件
            try
            {
                sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, code);
                sw.Write(str);
                sw.Flush();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sw.Close();
                Response.Write("恭喜<a href=htm/" + fileName + " target=_blank>" + fileName + "</a>已經(jīng)生成,保存在htm文件夾下!");
            }


        }

        protected void Button2_Click(object sender, EventArgs e)
        {
             Encoding code = Encoding.GetEncoding("utf-8");
            StreamReader sr = null;
            StreamWriter sw = null;
            string str = null;

            //讀取遠(yuǎn)程路徑
            WebRequest temp = WebRequest.Create(txtUrl.Text.Trim());
            WebResponse myTemp = temp.GetResponse();
            sr = new StreamReader(myTemp.GetResponseStream(), code);
            //讀取
            try
            {
                sr = new StreamReader(myTemp.GetResponseStream(), code);
                str = sr.ReadToEnd();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sr.Close();
            }
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm";

            //寫入
            try
            {
                sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, code);
                sw.Write(str);
                sw.Flush();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sw.Close();
                Response.Write("恭喜<a href=htm/" + fileName + " target=_blank>" + fileName + "</a>已經(jīng)生成,保存在htm文件夾下!");
            }

        }
        }
   
}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
excel批量導(dǎo)入數(shù)據(jù)
ASP.NET中序列化與反序列化-以顯示上一次登錄的信息為例
ASP.NET生成HTML初級(jí)解決方案
C#中的cookie詳解
asp.net控件開發(fā)基礎(chǔ)(2)
ASP.NET頁面——視圖狀態(tài)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服