#region 根据字符串生成HTML静态页
///
/// 根据字符串生成HTML静态页
///
/// html格式的字符
/// 生成的HTML静态页路径
///
public static string WriteHtmlFile(string TemplateStr, string OutPutPath)
{
Encoding encoding = Encoding.GetEncoding("gb2312");
///
/// 根据字符串生成HTML静态页
///
/// html格式的字符
/// 生成的HTML静态页路径
///
public static string WriteHtmlFile(string TemplateStr, string OutPutPath)
{
Encoding encoding = Encoding.GetEncoding("gb2312");
//StreamWriter实现一个 TextWriter,使其以一种特定的编码向流中写入字符,命名空间Syste.IO。
StreamWriter sw = null;
StreamWriter sw = null;
//生成的文件名
string newName = "AD.htm";
string newName = "AD.htm";
//写文件
try
{
sw = new StreamWriter(OutPutPath + newName, false, encoding);
sw.Write(TemplateStr);
try
{
sw = new StreamWriter(OutPutPath + newName, false, encoding);
sw.Write(TemplateStr);
//清理当前编写器的所有缓存区,并将缓存数据写入基础流。
sw.Flush();
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
finally
{
sw.Close();
sw.Dispose();
}
sw.Flush();
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
finally
{
sw.Close();
sw.Dispose();
}
return newName;
}
#endregion
#endregion
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23109131/viewspace-700346/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23109131/viewspace-700346/
本文介绍了一个简单的C#方法,用于将HTML格式的字符串转换为HTML静态页面文件。该方法使用StreamWriter来创建并写入文件,支持GB2312编码。通过此方法,可以方便地从动态生成的内容创建静态网页。
1293

被折叠的 条评论
为什么被折叠?



