码迷,mamicode.com
首页 > Web开发 > 详细

.net写本地文件的一个方法

时间:2018-07-23 11:14:49      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:use   info   serve   public   mode   代码   static   exist   delete   

整理代码,.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写本地文件的一个方法

标签:use   info   serve   public   mode   代码   static   exist   delete   

原文地址:https://www.cnblogs.com/Lvkang/p/9352976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!