C#把一段HTML代码保存为.HTML文件

 1 #region 保存文件
 2 public void SaveFile(StringBuilder strHtml)
 3 {
 4 string tpxxID = Request.QueryString["FBWZID"];
 5 try
 6 {
 7 Model.TP_TPXX mTpxx = cTpxx.GetModel(tpxxID);
 8 string f = System.Configuration.ConfigurationManager.AppSettings
 9 
10 ["SaveFilePath"] + "files\\" + 
11 
12 System.Configuration.ConfigurationManager.AppSettings["SysCode"]; //web配置文件中配置的地址
13 //保存地址
14 string FilePath = f + "\\网站发布\\" + string.Format("{0:yyyy-MM-dd}"
15 
16 DateTime.Now) + "\\" + tpxxID + "\\" + mTpxx.TPBT + ".html";
17 
18 
19 if (!Directory.Exists(Path.GetDirectoryName(FilePath)))
20 {
21 //创建路径
22 Directory.CreateDirectory(Path.GetDirectoryName(FilePath));
23 }
24 
25 //创建HTML文件,写入HTML,全路径带扩展名
26 File.Delete(FilePath);
27 File.AppendAllText(FilePath, strHtml.ToString(), Encoding.Default);
28 
29 ClientScript.RegisterClientScriptBlock(GetType(), "script""<script 
30 
31 type='text/javascript' defer>alert('发布成功!');newCommon.WindowClose
32 
33 ();</script>");
34 
35 }
36 catch (Exception ex)
37 {
38 
39 throw;
40 }
41 }
42 #endregion
posted @ 2015-04-15 17:20  Tz__C  阅读(1621)  评论(0编辑  收藏  举报