|
§‖ Date ::.. |
|
|
|
§‖ BLog Info ::.. |
|
| |
|
§‖ New BLog ::.. |
|
|
§‖ Comment ::.. |
|
|
§‖ Message ::.. |
|
|
§‖ User Login ::.. |
|
|
§‖ Search ::.. |
|
|
§‖ Links ::.. |
|
| |
 |
|
|
 |
 |
///
/// 生成静态页面以及内容分页
///
public void CreateHtml_FenYe()
{
//获取当前的年月日
string Datetime = DateTime.Now.ToString("yyyyMMdd");
//生成静态页面的名字
string strDatetime = DateTime.Now.ToString("yyyyMMddhhmmss");
//这里根据自己的需要增添标签
//标题
string strTile = txt_Tile.Text.Trim();
//内容
string strContext = Convert.ToString(this.editkj1.Getvalue());
//分解内容为字符串数组作为分页内容
string[] strContextchars = strContext.Split(new char[] { '^' });
//记录数组上限
int UPCount = strContextchars.Length;
//*********************创建日期文件夹开始*****************************
//创建文件夹路径
string filePath = Server.MapPath("~/RC/html/" + Datetime);
if (!Directory.Exists(filePath))
{
DirectoryInfo dif = Directory.CreateDirectory(filePath);
}
//*********************创建日期文件夹结束*****************************
//*********************拆分静态页开始***********************************************
try
{
for (int i = 0; i < strContextchars.Length; i++)
{
//*************读取模板开始**********************************************
StringBuilder html = new StringBuilder();
//创建读取对象并用中文编码
StreamReader readTemplate = new StreamReader(Server.MapPath("~/RC/html/" + "shownews_teleple.htm"), Encoding.GetEncoding("gb2312"));
//读取每一行
string strLine;
while ((strLine = readTemplate.ReadLine()) != null)
{
html.Append(strLine);
}
readTemplate.Close();
//*************读取模板结束*********************************************
//建立分页表
string strTablePage = "";//分页标签
string WebPath = "";
//替换标签
html = html.Replace("News_Title", strTile);
//替换内容
html = html.Replace("news_code", strContextchars[i]);
//替换发布时间
html = html.Replace("lbl_NewsDate", System.DateTime.Now.ToString());
//替换来源
html = html.Replace("come", txt_Come.Text);
html = html.Replace("lbl_NewsCome", txt_Come.Text);
//替换作者
html = html.Replace("author", txt_Author.Text);
//******************************建立数字分页开始********************************************************
string strPageNumber = "";
//Response.Write("页数="+UPCount);
for (int count = 1; count <= UPCount; count++)
{
if (count == 1)
{
strPageNumber = strPageNumber + "【" + count + "】";
}
else
{
int k = count - 1;
strPageNumber = strPageNumber + "【" + count + "】";
}
}
//*******************************建立数字分页结束********************************************************
//*******************************建立上一页和下一页开始********************************************************
//根据内容拆分生成静态页
for (int j = 0; j < UPCount; j++)
{
//如果内容没有分页
if (UPCount == 1)
{
WebPath = Server.MapPath("~/RC/html/") + Datetime + "\\" + strDatetime + ".html";
html = html.Replace("Pageing", "");
}
else//如果有分页
{
//写页码
strTablePage = strTablePage.Replace("PageNumber", strPageNumber);
if (i == 0)
{
WebPath = Server.MapPath("../../RC/html/") + Datetime + "\\" + strDatetime + ".html";
}
else
{
WebPath = Server.MapPath("../../RC/html/") + Datetime + "\\" + strDatetime + "_" + i + ".html";
}
//处理是否实现前一页第一页不显示
if (i == 0)
{
strTablePage = strTablePage.Replace("UpPage", "上一页");
}
if (i == 1)
{
strTablePage = strTablePage.Replace("UpPage", "上一页");
}
else
{
int m = i - 1;
strTablePage = strTablePage.Replace("UpPage", "上一页");
}
//最后一个不现实DownPage
if (i == UPCount - 1)
{
strTablePage = strTablePage.Replace("DownPage", "下一页" + "");
}
if (i != j - 1)
{
int n = i + 1;
strTablePage = strTablePage.Replace("DownPage", "下一页" + "");
}
else
{
int o = j;
strTablePage = strTablePage.Replace("DownPage", "下一页");
}
//替换分页把内容写入
html = html.Replace("Pageing", strTablePage);
}
//*******************************建立上一页和下一页结束********************************************************
//***********************写入文件开始********************************************
//建立文件
FileInfo fileInformation = new FileInfo(WebPath);
//打开并只写
FileStream fs = fileInformation.OpenWrite();
//建立写入文件流
StreamWriter fileWrite = new StreamWriter(fs, System.Text.Encoding.Default);
//把替换的内容写入文件
fileWrite.WriteLine(html);
//清空
fileWrite.Flush();
//关闭对象
fileWrite.Close();
//************************写入文件结束*******************************************
}
}
//********************拆分静态页结束***********************************************
}
catch (Exception ex)
{
throw ex;
}
}
silence520 by 2008-8-13 14:31:00 阅读全文 | 回复(0) | 引用通告 | 编辑
|
|
| 发表评论:
| | | |