//生成静态网页
string path = ServerMapPath(~/news/ + folder + /)
string file_template_name = ServerMapPath(~/news/) //新闻模版文件
string file_template_content = ;
StreamReader sr_reader = new StreamReader(file_template_name EncodingGetEncoding(gb))
file_template_content = sr_readerReadToEnd()
sr_readerClose()
string[] subContent = FileSplit(content)
string file_content = ;
int pageNum = ;
while (pageNum < && subContent[pageNum] != && subContent[pageNum] != null)
pageNum++;
for (int index = ; index < pageNum; index++)
{
file_content = file_template_content;
file_content = file_contentReplace($$category list_departmentSelectedItemText) //新闻类别
file_content = file_contentReplace($$title title) //新闻标题
file_content = file_contentReplace(<!来源$$author> 来源 + author) //作者
file_content = file_contentReplace($$time time) //添加时间
file_content = file_contentReplace($$content subContent[index]) //新闻正文
string pageLink = ;
int firstPage = ;
//生成页码
if (index > ) firstPage = index ;
for (int i = firstPage; i < index + && i < pageNum; i++)
{
if (i == index)
pageLink = pageLink + [ + (index + ) + ] + ;
else pageLink = pageLink + <a + htmlfilename + i + >[ + (i + ) + ]</a> ;
}
if (index < pageNum )
pageLink = pageLink + <a + htmlfilename + (index + ) + > + 下一页 + </a> ;
if (index > )
pageLink = <a + htmlfilename + (index ) + > + 上一页 + </a> + pageLink;
file_content = file_contentReplace(<! $$pageLink > pageLink)
if (index == pageNum &&attachment_filename != null && attachment_filename != StringEmpty)
{
string[] attachment = attachment_filenameSplit(new char[] { | })
string attachmenthtml = <a + attachment[] + > + attachment[] + </a>;
for (int j = ; j < attachmentLength; j++)
attachmenthtml = attachmenthtml + <br/> <a + attachment[j] + > + attachment[j] + </a>;
file_content = file_contentReplace($$attachment attachmenthtml)
}
StreamWriter sw = new StreamWriter(path + htmlfilename + index + false EncodingGetEncoding(gb))
swWrite(file_content)
swFlush()
swClose()
}
HyperLinkText = 预览 + title;
HyperLinkNavigateUrl = /news/ + folder + / + htmlfilename + + ;
HyperLinkVisible = true;
txt_timeText = DateTimeNowToString(yyyyMMdd)
txt_titleText = ;
txt_authorText = ;
FreeTextBoxText = ;
}
catch (Exception e)
{
}
}
//将正文分成多个页面
protected string[] FileSplit(string fileContent)
{
int fileIndex = ;
string[] splitedFile = new string[];
while (fileContentLength > && fileIndex < ) //每页至少个字符
{
if (fileContentIndexOf(<P> ) < ) break;
splitedFile[fileIndex] = fileContentSubstring( fileContentIndexOf(<P> ))
fileContent = fileContentRemove( splitedFile[fileIndex]Length)
fileIndex++;
}
splitedFile[fileIndex] = fileContent; //超过页剩下部分全放第十页
return splitedFile;
}
}