.net寫本地文件的一個方法
阿新 • • 發佈:2018-07-23
方法 pan utf-8 str n) html name ring adf
整理代碼,.net在本地寫html文件的一個方法,代碼如下
1 public static void WriteFile(string FilePath, string FileInfo, string Encode = "GB2312") 2 { 3 try 4 { 5 if (System.IO.File.Exists(FilePath)) System.IO.File.Delete(FilePath); 6 System.IO.File.WriteAllText(FilePath, FileInfo, Encoding.GetEncoding(Encode));7 } 8 catch (Exception) 9 { 10 } 11 }
調用方法如下:
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");
.net寫本地文件的一個方法