乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      asp.net生成靜態(tài)頁(yè)的兩種方法

       wangn 2010-09-16

      Default.aspx頁(yè)面:

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

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

      <html xmlns="http://www./1999/xhtml" >
      <head id="Head1" runat="server">
          <title>Asp.net生成靜態(tài)頁(yè)的兩個(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文件夾下!");
                  }

              }
              }
         
      }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多