html文件清除,生成丶清除指定目录下的HTML文件

///

/// 事件:生成HTML按钮

///

///

///

protected void lbCreateHTML_Click(object sender, EventArgs e)

{

List MDnews = NewsInfoManager.GetAllNewsInfo();

foreach (NewsInfo item in MDnews)

{

Generator(item);

}

BindNews();

ltrMsg.Text = "HTML页面已全部生成";

}

///

/// 方法:根据HTML模版生成静态HTML文件

///

///

private void Generator(NewsInfo entity)

{

string id = NewsInfoManager.GetEntityByTitleAndTile(entity) + "";

//读模板文件

string path = Server.MapPath(@"~\Templates\article.htm");

string temp = File.ReadAllText(path, Encoding.Default);

//替换

temp = temp.Replace("#title#", entity.Title);

temp = temp.Replace("#time#", entity.AddTime.ToString("F"));

temp = temp.Replace("#content#", entity.Content);

temp = temp.Replace("#msg#", DateTime.Now.ToString() + Environment.NewLine + "作者:南方学院");

//写入html文件中

path = Server.MapPath(string.Format(@"~\Articles\{0}.html", id));

if (File.Exists(path)) //如果存在,删除

{

File.Delete(path);

}

File.WriteAllText(path, temp, Encoding.Default);

}

///

/// 事件:删除指定目录下的HTML文件

///

///

///

protected void lbDeleteHTML_Click(object sender, EventArgs e)

{

System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Server.MapPath("~/Articles/"));

FileInfo[] files = di.GetFiles("*.html");

foreach (FileInfo item in files)

{

item.Delete();

}

BindNews();

ltrMsg.Text = "HTML已全部清除";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值