我的代码如下:
StreamWriter SWNewsFile = new StreamWriter(strNewsFilePath, false, System.Text.Encoding.GetEncoding("gb2312"));
            SWNewsFile.Write(sbTempletContent.ToString());
            SWNewsFile.Close();当生成完以后.htm页出现了如下代码(只拷一部份):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="images/web.css" rel="stylesheet" type="text/css">
<title>NewsTitle</title>
<script  language="javascript">
请高手指点如何解决。

解决方案 »

  1.   

    在生成静态页之前,把这些字符串html格式化一下,就是替换。
      

  2.   

    Public Function Encode(ByVal strParamer As String) As String
            strParamer = Replace(strParamer, "&", "&")
            strParamer = Replace(strParamer, "'", "''")
            strParamer = Replace(strParamer, " ", " ")
            strParamer = Replace(strParamer, "<", "&lt;")
            strParamer = Replace(strParamer, ">", "&gt;")
            strParamer = Replace(strParamer, "\n", "<br>")
            Return strParamer
        End Function
        Public Function Decode(ByVal strParamer As String) As String
            strParamer = Replace(strParamer, "<br>", "\n")
            strParamer = Replace(strParamer, "&gt;", ">")
            strParamer = Replace(strParamer, "&lt;", "<")
            strParamer = Replace(strParamer, "&nbsp;", " ")
            strParamer = Replace(strParamer, "''", "'")
            strParamer = Replace(strParamer, "&amp;", "&")
            Return strParamer
        End Function
      

  3.   

    关键是在生成的htm页里已经是这种代码了:
    &lt;html&gt;
    &lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot;&gt;
    &lt;link href=&quot;images/web.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
    &lt;title&gt;NewsTitle&lt;/title&gt;
    &lt;script  language=&quot;javascript&quot;&gt;
    没有机会再用Sever.HtmlDecode(...)了,并且在生成之前我用Response.Write(sbTempletContent.ToString());打印测试了源串,都没问题的。