整理代码,.net在本地写html文件的一个方法,代码如下

 public static void WriteFile(string FilePath, string FileInfo, string Encode = "GB2312")
{
try
{
if (System.IO.File.Exists(FilePath)) System.IO.File.Delete(FilePath);
System.IO.File.WriteAllText(FilePath, FileInfo, Encoding.GetEncoding(Encode));
}
catch (Exception)
{
}
}

调用方法如下:

var strFileCn = File.ReadFile(MapPath("order_model.html"), "utf-8");//构建html文件内容
strFileCn = strFileCn.Replace("#orderid#", orders.orderid);
strFileCn = strFileCn.Replace("#username#", orders.username);
var strRocFileName = "/ROC/" + orders.orderid + ".htm";//文件地址
strRocFileName = Server.MapPath(strRocFileName);

WriteFile(strRocFileName, strFileCn, "utf-8");

04-19 18:05
查看更多