using System.Net;
using System.Text;
using System.IO;
protected void Page_Load(object sender, EventArgs e)
{
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("/CSInterface/html/games.htm");
StreamReader sr = null;
string str = string.Empty;
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
}
catch (Exception exp)
{
str = "error";
sr.Close();
}
Response.Write(str);
}
本文展示了一个使用C#从指定路径读取HTML文件并将其内容输出到网页的例子。通过设置编码为GB2312,确保了中文内容能够正确显示。
1068

被折叠的 条评论
为什么被折叠?



