我想根据模办生成html页面,总是不成功,可能是编码的问题

handsomge 2005-01-14 02:11:56
string strTemplate = Server.MapPath( "") + "\\Doctemplate.htm";
StreamReader sr = new StreamReader( strTemplate,System.Text.Encoding.GetEncoding("GB2312"));
StreamWriter sW = File.CreateText(strTargetFile);

string input;
string Src="";
while ((input=sr.ReadLine())!=null)
{
Src +=input;
}
sr.Close();
Src.Replace( "{$Content}",TxtContent.Text.ToString());
sW.Write(Src);
sW.Close();
...全文
160 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
abctop321 2005-01-17
  • 打赏
  • 举报
回复
StreamWriter swFromFileTrueUTF8Buffer =
new StreamWriter(Server.MapPath("abc")+ "\\a.html",
true, System.Text.Encoding.UTF8,512);
swFromFileTrueUTF8Buffer.Write("你想输出的");
swFromFileTrueUTF8Buffer.Flush();
swFromFileTrueUTF8Buffer.Close();
nga96 2005-01-17
  • 打赏
  • 举报
回复
顶,
nga96 2005-01-15
  • 打赏
  • 举报
回复
gi
jun_01 2005-01-14
  • 打赏
  • 举报
回复
或者生成一个同样是GB2312编码的字符串,用来替换,也许就可以了,呵呵
jun_01 2005-01-14
  • 打赏
  • 举报
回复
Src.Replace( "{$Content}",TxtContent.Text.ToString());
==========================================
你把"{$Content}"放到一个字符串里试试.
Fibona 2005-01-14
  • 打赏
  • 举报
回复
如果不指定编码,则替换不成功,如果指定了某一个,有的汉字变成乱码

是不是你的编码方式不对?
cnlike 2005-01-14
  • 打赏
  • 举报
回复
string strTemplate = Server.MapPath("Doctemplate.htm");
using (StreamReader sr = new StreamReader(strTemplate))
{
string content = sr.ReadToEnd().Replace("{$Content}", "我的内容");
using (System.IO.FileStream fs = new FileStream(Server.MapPath(System.DateTime.Now.ToString("HHmmss") + ".htm"), System.IO.FileMode.OpenOrCreate))
{
byte[] bs = System.Text.Encoding.GetEncoding("GB2312").GetBytes(content);
fs.Write(bs, 0, bs.Length);
}
}
handsomge 2005-01-14
  • 打赏
  • 举报
回复
如果不指定编码,则替换不成功,如果指定了某一个,有的汉字变成乱码
handsomge 2005-01-14
  • 打赏
  • 举报
回复
生成文件是成功的,替换不成功
jun_01 2005-01-14
  • 打赏
  • 举报
回复
什么错误啊? 是不是权限问题?

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧