zoukankan
html css js c++ java
ASP.NET实现新闻页面的分页功能[生成静态版]
//
生成静态网页
string
path
=
Server.MapPath(
"
~/news/
"
+
folder
+
"
/
"
);
string
file_template_name
=
Server.MapPath(
"
~/news/template.htm
"
);
//
新闻模版文件
string
file_template_content
=
""
;
StreamReader sr_reader
=
new
StreamReader(file_template_name, Encoding.GetEncoding(
"
gb2312
"
));
file_template_content
=
sr_reader.ReadToEnd();
sr_reader.Close();
string
[] subContent
=
FileSplit(content);
string
file_content
=
""
;
int
pageNum
=
0
;
while
(pageNum
<
10
&&
subContent[pageNum]
!=
""
&&
subContent[pageNum]
!=
null
)
pageNum
++
;
for
(
int
index
=
0
; index
<
pageNum; index
++
)
{
file_content
=
file_template_content;
file_content
=
file_content.Replace(
"
$$category
"
, list_department.SelectedItem.Text);
//
新闻类别
file_content
=
file_content.Replace(
"
$$title
"
, title);
//
新闻标题
file_content
=
file_content.Replace(
"
<!--来源:$$author-->
"
,
"
来源:
"
+
author);
//
作者
file_content
=
file_content.Replace(
"
$$time
"
, time);
//
添加时间
file_content
=
file_content.Replace(
"
$$content
"
, subContent[index]);
//
新闻正文
string
pageLink
=
""
;
int
firstPage
=
0
;
//
生成页码
if
(index
>
2
) firstPage
=
index
-
2
;
for
(
int
i1
=
firstPage; i1
<
index
+
3
&&
i1
<
pageNum; i1
++
)
{
if
(i1
==
index)
pageLink
=
pageLink
+
"
[
"
+
(index
+
1
)
+
"
]
"
+
"
"
;
else
pageLink
=
pageLink
+
"
<a href=
"
+
htmlfilename
+
i1
+
"
.htm>[
"
+
(i1
+
1
)
+
"
]</a>
"
;
}
if
(index
<
pageNum
-
1
)
pageLink
=
pageLink
+
"
<a href=
"
+
htmlfilename
+
(index
+
1
)
+
"
.htm>
"
+
"
下一页
"
+
"
</a>
"
;
if
(index
>
0
)
pageLink
=
"
<a href=
"
+
htmlfilename
+
(index
-
1
)
+
"
.htm>
"
+
"
上一页
"
+
"
</a>
"
+
pageLink;
file_content
=
file_content.Replace(
"
<!-- $$pageLink -->
"
, pageLink);
if
(index
==
pageNum
-
1
&&
attachment_filename
!=
null
&&
attachment_filename
!=
String.Empty)
{
string
[] attachment
=
attachment_filename.Split(
new
char
[]
{
'
|
'
}
);
string
attachmenthtml
=
"
<a href=
"
attachment
/
"
+ attachment[0] +
""
>
"
+
attachment[
0
]
+
"
</a>
"
;
for
(
int
j
=
1
; j
<
attachment.Length; j
++
)
attachmenthtml
=
attachmenthtml
+
"
<br/> <a href=
"
attachment
/
"
+ attachment[j] +
""
>
"
+
attachment[j]
+
"
</a>
"
;
file_content
=
file_content.Replace(
"
$$attachment
"
, attachmenthtml);
}
StreamWriter sw
=
new
StreamWriter(path
+
htmlfilename
+
index
+
"
.htm
"
,
false
, Encoding.GetEncoding(
"
gb2312
"
));
sw.Write(file_content);
sw.Flush();
sw.Close();
}
HyperLink1.Text
=
"
预览:
"
+
title;
HyperLink1.NavigateUrl
=
"
../news/
"
+
folder
+
"
/
"
+
htmlfilename
+
"
0
"
+
"
.htm
"
;
HyperLink1.Visible
=
true
;
txt_time.Text
=
DateTime.Now.ToString(
"
yyyy-MM-dd
"
);
txt_title.Text
=
""
;
txt_author.Text
=
""
;
FreeTextBox1.Text
=
""
;
}
catch
(Exception e)
{
}
}
//
将正文分成多个页面
protected
string
[] FileSplit(
string
fileContent)
{
int
fileIndex
=
0
;
string
[] splitedFile
=
new
string
[
10
];
while
(fileContent.Length
>
1500
&&
fileIndex
<
9
)
//
每页至少1500个字符
{
if
(fileContent.IndexOf(
"
<P>
"
,
1500
)
<
0
)
break
;
splitedFile[fileIndex]
=
fileContent.Substring(
0
, fileContent.IndexOf(
"
<P>
"
,
1500
));
fileContent
=
fileContent.Remove(
0
, splitedFile[fileIndex].Length);
fileIndex
++
;
}
splitedFile[fileIndex]
=
fileContent;
//
超过9页,剩下部分全放第十页
return
splitedFile;
}
}
查看全文
相关阅读:
GUIX 创建工程注意事项
VS 中bool和BOOL的区别
git 在Windows上的应用
rt-thread 相关网站地址
tcp client
VS2015 下载地址
软件各种协议比较(GPL、AGPL、LGPL、Apache、Zlib/Libpng、BSD、MIT)
UILabel标签
UIbutton
数据互转
原文地址:https://www.cnblogs.com/sujingnan/p/1121478.html
最新文章
分层自动化测试 分类: 移动测试 2015-07-15 16:20 11人阅读 评论(0) 收藏
分层自动化测试
Selenium学习笔记之004:使用Selenium IDE录制脚本并分析unittest框架 分类: Selenium 2015-07-15 00:35 17人阅读 评论(0) 收藏
Selenium学习笔记之004:使用Selenium IDE录制脚本并分析unittest框架
初步使用git clone代码到本地 分类: Git系列 2015-07-14 15:29 2人阅读 评论(0) 收藏
初步使用git clone代码到本地
Selenium学习笔记之003:Web UI自动化知识点整理
截图代码
ios动画
一个正则表达式测试(只可输入中文、字母和数字)
热门文章
企业版导致无法安装的原因
SSH HTTPS 公钥、秘钥、对称加密、非对称加密、 总结理解(有助于网络层理解)
iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
关注的比较好的博客 和 网站
UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout 还有drawRect方法
控制器一些方法的执行顺序的测试
xib文件加载控制器View的一些原理
scons
tar gz压缩文件为指定大小
rm 递归删除文件夹下.o文件
Copyright © 2011-2022 走看看