zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    神马搜索 面试小结
    我的第一篇paper
    【转载】技巧:Vim 的纵向编辑模式
    实习求职小结
    将博客园界面打造成Hexo经典主题Light
    试一下Markdown
    四色标记算法
    射雕三部曲的优美片段
    Docker
    Sublime Text 3 文档
  • 原文地址:https://www.cnblogs.com/zecVip/p/4429174.html
Copyright © 2011-2022 走看看