国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.net(C#)讀取數據庫并生成JS文件制作首頁圖片切換效果(附demo源

2024-07-10 12:47:18
字體:
來源:轉載
供稿:網友

本文實例講述了Asp.net(C#)讀取數據庫并生成JS文件制作首頁圖片切換效果的方法。,具體如下:

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Text;using System.IO;public partial class _Default : System.Web.UI.Page{  protected void Page_Load(object sender, EventArgs e)  {  }  /// <summary>  /// 利用模板生成靜態頁面  /// </summary>  /// <param name="strTitle">標題</param>  /// <param name="strText">作者</param>  /// <param name="strContent">發布時間</param>  /// <param name="strAuthor">內容</param>  /// <returns>生成頁面名稱</returns>  public static string WriteFile(string strTitle, string strAuthor, string strDate, string strContent)  {    string path = HttpContext.Current.Server.MapPath("~/");    Encoding code = Encoding.GetEncoding("gb2312");    // 讀取模板文件    string temp = HttpContext.Current.Server.MapPath("~/Template.html");    StreamReader sr = null;    StreamWriter sw = null;    string str = "";    try    {      sr = new StreamReader(temp, code);      str = sr.ReadToEnd(); // 讀取文件    }    catch (Exception exp)    {      HttpContext.Current.Response.Write(exp.Message);      HttpContext.Current.Response.End();      sr.Close();    }    Random rd = new Random();    string strRd = rd.Next(0, 9999).ToString();    string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + strRd + ".html";    DateTime dtNow = DateTime.Now;    // 替換內容    str = str.Replace("$biaoti", strTitle);    str = str.Replace("$author", strAuthor);    str = str.Replace("$datetime", strDate);    str = str.Replace("$content", strContent);    // 寫文件    try    {      string pathUrl = path + dtNow.Year + "http://" + dtNow.Month + "http://" + dtNow.Day;      if (!Directory.Exists(pathUrl))      {        Directory.CreateDirectory(pathUrl);      }      sw = new StreamWriter(pathUrl + "http://" + htmlfilename, false, code);      sw.Write(str);      sw.Flush();    }    catch (Exception ex)    {      HttpContext.Current.Response.Write(ex.Message);      HttpContext.Current.Response.End();    }    finally    {      sw.Close();    }    return dtNow.Year.ToString() + "/" + dtNow.Month.ToString() + "/" + dtNow.Day.ToString() + "/" + htmlfilename;  }  protected void Button1_Click(object sender, EventArgs e)  {    WriteFile("title" , "ttttttt" , "2011-09-27", "測試 <br>");  }}

Template.html

<table>  <tr>    <td align="center">$biaoti</td>  </tr>  <tr>    <td align="center">作者:$author  發布時間:$datetime</td>  </tr>  <tr>    <td>$content</td>  </tr></table>

思路:首先讀取數據庫中圖片,鏈接,說明文字等數據,然后將讀取到的數據寫入首頁圖片切換效果的JS文件。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 固始县| 雷波县| 唐山市| 天峨县| 舟曲县| 隆子县| 含山县| 海淀区| 安宁市| 海门市| 新密市| 施秉县| 客服| 涞水县| 延津县| 长沙县| 化州市| 昆明市| 海晏县| 米泉市| 林周县| 分宜县| 香河县| 永福县| 房产| 永川市| 南陵县| 顺平县| 长泰县| 马山县| 平安县| 太仆寺旗| 山丹县| 阜宁县| 应用必备| 体育| 嵩明县| 新余市| 祁连县| 南昌市| 彰武县|