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);
}
}
查看全文
相关阅读:
Jenkins和pipeline
Docker摘要
javascript文件加载模式与加载方法
Pre-shared key
持续集成CI相关的几个概念
Fetch诞生记
Content Security Policy介绍
vivalidi 一款由Web技术诞生的Web浏览器
Javascript async异步操作库简介
Polymer初探
原文地址:https://www.cnblogs.com/mickey/p/796146.html
最新文章
npm命令总结
-bash: /usr/local/bin/react-native: No such file or directory
Git 命令解释优秀博文转摘
Jenkins pipeline shared library
Linux文件权限设置
JQuery Rest客户端库
JSViews--JQuery系的MVVM框架
MobX响应式编程库
Lua Doc生成工具
Slash and BackSlash 记忆法
热门文章
FFI
PMD -- An extensible cross-language static code analyzer.
jQuery two way bindings(双向数据绑定插件)
partial.js client-side routing(客户端路由-基于HTML5 SPA特性的历史API)
Prolog 逻辑推导语言
angularjs路由path方式实现原理探究
JS数据结构库
GIT好文搜藏
网页浏览 infinite scroll效果知识
A/B测试
Copyright © 2011-2022 走看看