zoukankan
html css js c++ java
ASP.NET 生成静态html页之扩展(按年月目录)
在他人的基础上更改的!
代码如下:
详细内容看代码
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.IO;
using
System.Text;
using
System.Data.SqlClient;
/**/
///
<summary>
///
CreateHtml 的摘要说明
///
</summary>
public
class
CreateHtml
{
public
CreateHtml()
{
//
//
TODO: 在此处添加构造函数逻辑
//
}
public
static
bool
WriteFile(
string
title,
string
nfrom,
string
publishtime,
string
publisher,
string
contont)
{
//
//
以下定义
//
获取当前Web目录
//
模版文件
//
格式化文件名
//
用于生成年份目录
//
用于生成月份目录
//
从temple.html读取得字符
string
path
=
HttpContext.Current.Server.MapPath(
"
.
"
)
+
"
/news/
"
;
string
temp
=
path
+
"
temple.html
"
;
string
filename
=
DateTime.Now.ToString(
"
yyyyMMddHHmmss
"
)
+
"
.html
"
;
string
YYYYpath
=
path
+
DateTime.Now.Year.ToString();
string
MMpath
=
YYYYpath
+
"
/
"
+
DateTime.Now.Month.ToString();
string
str
=
""
;
StreamReader sr
=
null
;
StreamWriter sw
=
null
;
Encoding code
=
Encoding.GetEncoding(
"
gb2312
"
);
try
{
//
read file
sr
=
new
StreamReader(temp, code);
str
=
sr.ReadToEnd();
}
catch
(Exception ex)
{
HttpContext.Current.Response.Write(
"
读取错误
"
+
ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sr.Close();
}
//
replace
str
=
str.Replace(
"
{$title}
"
, title);
str
=
str.Replace(
"
{$nfrom}
"
, nfrom);
str
=
str.Replace(
"
{$publishtime}
"
, publishtime);
str
=
str.Replace(
"
{$publisher}
"
, publisher);
str
=
str.Replace(
"
{$contont}
"
, contont);
//
write
try
{
//
if Directory not Exists else Create Directory;
if
(
!
Directory.Exists(YYYYpath))
{
Directory.CreateDirectory(YYYYpath);
if
(
!
Directory.Exists(MMpath))
{
Directory.CreateDirectory(MMpath);
}
}
sw
=
new
StreamWriter(MMpath
+
"
/
"
+
filename,
false
, code);
sw.Write(str);
sw.Flush();
}
catch
(Exception ex)
{
HttpContext.Current.Response.Write(
"
写入失败
"
+
ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
//
update myurl
StringBuilder url
=
new
StringBuilder();
url.Append(
"
news/
"
);
url.Append(DateTime.Now.Year.ToString());
url.Append(
"
/
"
);
url.Append(DateTime.Now.Month.ToString());
url.Append(
"
/
"
);
url.Append(filename);
SqlConnection conn
=
null
;
try
{
conn
=
Db.createConnection();
//
从Db的静态方法得到SqlConnection
conn.Open();
SqlCommand cmd
=
new
SqlCommand(
"
update news set myurl='
"
+
url
+
"
'
"
,conn);
if
(
1
==
cmd.ExecuteNonQuery())
{
HttpContext.Current.Response.Write(
"
成功插入url<br/>
"
);
}
}
catch
(Exception ex)
{
HttpContext.Current.Response.Write(
"
更新url错误
"
+
ex.Message);
HttpContext.Current.Response.End();
}
finally
{
conn.Close();
}
return
true
;
}
}
查看全文
相关阅读:
Maccms后门分析复现(并非官网的Maccms){10.15 第二十二天}
BurpSuite详解
java数据类型转换
java常用关键字(static、final、this、super)
工厂设计模式
java singleton(单例设计模式)
完成一个springboot项目的完整总结------三
完成一个springboot项目的完整总结-------二
完成一个springboot项目的完整总结一
ER图的构建
原文地址:https://www.cnblogs.com/kokoliu/p/554527.html
最新文章
UUID
安全运营
安全开发流程(SDL)
互联网业务安全
做好互联网企业的安全工作
svn window下过滤文件(如配置文件等)
MySQL函数
给电脑C盘系统盘瘦身的四种方法
使用git(window)在github上存项目教程
PHP判断iPhone、iPad、Android、PC设备的方法
热门文章
Linux 常识
coreseek常见错误原因及解决方法
mysql+ssh 配置(转载)
伪静态页面(10.24 第二十六天)
MySQL报错注入函数汇总及常用注入语句
WEB前段(HTML+JS),后端(MYSQL+PHP)开发基础
WEB基础知识
使用BP爆破有token值的密码(10.17 第二十三天)
PHP操作MYSQL数据库(10.11 第十九天)
sudo 提权漏洞(CVE-2019-14287)复现 (10.16 第二十二天)
Copyright © 2011-2022 走看看