62,046
社区成员
发帖
与我相关
我的任务
分享
public static bool WriteFile(string strText, string strContent, string strAuthor)
{
string path = HttpContext.Current.Server.MapPath("Html/");
System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("Html/ActionDetails.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();
}
string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
// 替换内容 // 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("$title$", strText); //模板页中的ShowArticle
str = str.Replace("$time$", strText);
str = str.Replace("$content$", strContent);
// 写文件
try
{
sw = new StreamWriter(path + htmlfilename, false, code); //为false时候是覆盖,true为追加
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
return true;
}
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文?/title>
<link href="../css/css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="xxl_moban" id="content_xxl">
<div id="txt_xxl">
<h2>了解我们最新的印刷工艺与产品生产过程中的解决方案…?/h2>
<h1>? titititititititle</h1>
<p>?time$?/p>
<h3 class="conent">datatadatadatadatadata</h3>
</div>
</div>
</body>
</html
>
public static bool WriteFile(string strText, string strContent, string strAuthor)
{
string path = HttpContext.Current.Server.MapPath("Html/");
System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");
// 读取模板文件
............
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="../css/css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="xxl_moban" id="content_xxl">
<div id="txt_xxl">
<h2>了解我们最新的印刷工艺与产品生产过程中的解决方案……</h2>
<h1>◎ $title$</h1>
<p>【$time$】</p>
<h3 class="conent">$content$</h3>
</div>
</div>
</body>
</html>