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;
}结果发现生成的Html代码是这样的<!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>很多标签都变成了“?”
解决方案 »
- win2008 64位+iis7共享内存问题
- 怎样控制treeview 中NavigateUrl指向不同的页面
- IIS使用域认证的问题,急,请高手出来指点!
- 请教关于使用Guid(SQL中的Uniqueidentifier)列作为存储过程参数的问题?
- 高手快来帮忙啊~~
- datagrid列标题修改问题
- 菜鸟问:关于表单提交插入数据库的问题
- 急!!!请问asp.net beta 2 中如何利用Microsoft.ApplicationBlocks.Data访问数据库
- 思归,孟子!斑竹和高手们请看看这个帖子!求助!
- 如何过滤sql中的危险字符
- DevExpress.Web.ASPxGridView 分页问题
- .net生成静态页面的高手请进!!
<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>
为了方便调式,我是这么引用的
WriteFile("titititititititle", "datatadatadatadatadata", "contentcontentcontent");传入的值没有问题。
看了,是Unicode(utf-8)我想应该不是浏览器的问题吧,
有很多标签都变成了“?”,咋回事呢?
System.Text.Encoding code = System.Text.Encoding.GetEncoding("utf8");
调试看看str 中内容。
<META http-equiv=Content-Type content= "text/html; charset=gb2312 ">
看看
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" />
上面是GB2312,下面是UTF8,会是这个问题吗?楼主把编码统一一下试试吧