html语句乱码
StreamWriter rw=File.CreateText(Application.StartupPath+@ "\News.html ");
rw.WriteLine( " <meta http-equiv=\ "Content-Type\ " content=\ "text/html; charset=gb2312\ "> ");
rw.WriteLine( " <style type=text/css > ");
rw.WriteLine( " <!-- ");
rw.WriteLine( "body,td,th ");
rw.WriteLine( "{ ");
rw.WriteLine( "font-family: 宋体; ");
rw.WriteLine( "font-size: 16px; ");
rw.WriteLine( "color: #FFFFFF; ");
rw.WriteLine( "margin-top: 6px; ");
rw.WriteLine( "margin-left: 9px; ");
rw.WriteLine( "} ");
rw.WriteLine( "body ");
rw.WriteLine( "{ background-color: #000000; border:0 ;border-style: outset;}--> ");
rw.WriteLine( " </style> ");
rw.WriteLine( " <body onselectstart= 'return false ' oncontextmenu= 'return false '> ");
rw.WriteLine( " <marquee direction= 'left '> ");
rw.WriteLine( "份新教务文件,个待处理学生 ");
rw.WriteLine( " </marquee> ");
rw.WriteLine( " </body> ");
rw.Flush();
rw.Close();
用这段代码写成news.html后,用浏览器打开为乱码。
如果用txt方式打开然后重新用浏览器打开就好了。
非常的神奇,请高手指教。
[解决办法]
StreamWriter rw= new StreamWriter(Application.StartupPath+@ "\News.html ",Encoding.GetEncoding( "Gb2312 "));