C#中将文件保存为utf-8无bom格式
///<summary>
///保存生成html页面到相应路径
///</summary>
///<param name="Shtml">要写入的内容</param>
///<param name="TemplatePath">存储路径</param>
///<returns></returns>
publicstaticvoid WriteHtmlFile(string Shtml, string HtmlPath)
{
StreamWriter sw = null;
try
{
UTF8Encoding utf8 = new UTF8Encoding(false);
using (sw = new StreamWriter(HtmlPath, false, utf8))
{
sw.Write(Shtml);
}
}
catch
{
thrownewException("存储路径错误,请检查路径" + HtmlPath + "是否存在!");
}
finally
{
sw.Close();
}
}
来源:亦有软件