zoukankan
html css js c++ java
根据url地址生成静态页面
最近在做一个新闻系统,前台新闻页面要生成HTML静态页面,
自己找了一些资料,终于达到预期效果
现分享如下:
using
System.IO;
using
System.Text;
using
System.Net;
using
System.Configuration;
private
void
Button1_Click(
object
sender, System.EventArgs e)
{
Encoding code
=
Encoding.GetEncoding(
"
utf-8
"
);
StreamReader sr
=
null
;
StreamWriter sw
=
null
;
string
str
=
null
;
//
读取远程路径
WebRequest temp
=
WebRequest.Create(txtUrl.Text.Trim());
WebResponse myTemp
=
temp.GetResponse();
sr
=
new
StreamReader(myTemp.GetResponseStream(), code);
//
读取
try
{
sr
=
new
StreamReader(myTemp.GetResponseStream(), code);
str
=
sr.ReadToEnd();
}
catch
(Exception ex)
{
throw
ex;
}
finally
{
sr.Close();
}
string
path
=
HttpContext.Current.Server.MapPath(
"
../news
"
);
//
取得新闻当前文件夹
DateTime year
=
DateTime.Now;
string
years
=
Convert.ToString(year.Year);
//
当前年
string
month
=
Convert.ToString(year.Month);
//
当前月
string
CurrentPath
=
path
+
"
/
"
+
years;
//
设置当前年目录
if
(Directory.Exists(CurrentPath)
==
false
)
//
若该目录不存在,创建该目录
Directory.CreateDirectory(CurrentPath);
string
CurrentMonthPath
=
CurrentPath
+
"
/
"
+
month;
//
设置当前月目录
if
(Directory.Exists(CurrentMonthPath)
==
false
)
//
若该目录不存在,创建该目录
Directory.CreateDirectory(CurrentMonthPath);
string
fileName
=
DateTime.Now.ToString(
"
ddHHmmss
"
)
+
"
.htm
"
;
//
写入
try
{
sw
=
new
StreamWriter(CurrentMonthPath
+
"
/
"
+
fileName,
false
, code);
sw.Write(str);
sw.Flush();
}
catch
(Exception ex)
{
throw
ex;
}
finally
{
sw.Close();
Response.Write(
"
恭喜<a href=
"
+
CurrentMonthPath
+
"
/
"
+
fileName
+
"
target=_blank>
"
+
fileName
+
"
</a>已经生成,保存在htm文件夹下!
"
);
Response.Write(CurrentMonthPath
+
"
/
"
+
fileName);
}
}
查看全文
相关阅读:
Centos下Zookeeper的安装部署
Zookeeper入门
Redis高可用-主从,哨兵,集群
Redis入门
centos7 安装redis6.0.3
二叉树的遍历及常用算法
分享一个seata demo,讲两个个问题
互联网公司,我们需要什么样的中层技术管理以及996和程序员有多大关系?
Spring Boot微服务如何集成seata解决分布式事务问题?
软件服务架构的一些感悟
原文地址:https://www.cnblogs.com/mickey/p/796146.html
最新文章
Struts2使用Token避免表单重复提交(十三)
Struts2编写自定义验证拦截敏感词汇(十二)
Struts2利用验证框架实现数据验证(十一)
知识站说明
运维小哥之年终总结 [2019]
NFS服务部署及使用详述
Kubernetes内部域名解析的那些事儿
高版本Jenkins关闭跨站请求伪造保护(CSRF)
Jenkinsfile中定义的podTemplate中的容器执行kubectl命令权限不够问题解决
Node节点加入k8s集群
热门文章
Centos7部署k8s[v1.16]高可用[keepalived]集群
什么是DevOps ?
数据库容量信息查看语句
运维与开发的开车现场之MySQL5.7创建触发器报错解决过程
Dubbo+Zookeeper集群案例
数据结构与算法
Java 入土之路
调用Dubbo服务超时 Waiting server-side response timeout
树和森林
Zookeeper实现服务注册/发现
Copyright © 2011-2022 走看看