生成静态页
ReportCommonOperation里面
//生成静态页面
public void createReportCommonHtml(int RID)
{
ReportCommonOperation RCO = new ReportCommonOperation(RID);
if (RCO.RID == 0)
{
return;
}
//存放路径
string filepath = ConfigurationSettings.AppSettings["ReportCommonHtmlPath"];
string path = AppDomain.CurrentDomain.BaseDirectory + filepath;
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = AppDomain.CurrentDomain.BaseDirectory + "HtmlTemplet\\reportcommon.html";
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("$$$[InstiName]$$$", RCO.InstiName);
str = str.Replace("$$$[ReportType]$$$",RCO.ReportType);
str = str.Replace("$$$[ReportTime]$$$",RCO.ReporTime.ToString("yyyy-M-d"));
str = str.Replace("$$$[ReportMan]$$$", RCO.ReportMan);
str = str.Replace("$$$[Title]$$$",RCO.ReportTitle);
str = str.Replace("$$$[Reportcontent]$$$",RCO.ReportContent.ToString());
// 写文件
try
{
sw = new StreamWriter(path + RCO.RID.ToString().Trim() + ".html", false, code);
sw.Write(str);
sw.Flush();
string sql = "update ReportCommon set HtmlFileName = '" + RCO.RID.ToString().Trim() + ".html' where RID=" + RCO.RID.ToString().Trim();
SqlHelper.ExecuteNonQuery(sql);
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
}
模板
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta name="keywords" content="股票,A股,大盘,散户,股票公司"/>
<meta name="description" content="关于富易介绍。" />
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<link href="http://www.cnblogs.com/user/css/font.css" rel="stylesheet" type="text/css" />
<link href="http://www.cnblogs.com/user/css/indexcss.css" rel="stylesheet" type="text/css" /><title>
</title></head>
<body style="padding:0" oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false">
<div class="wrap" style="width:600px;padding-left:0px; float:inherit">
<div class="jdzxlfzh" style="width:612px; float:left; padding-left:0px">
<table class="table1" border="0" style="padding:0px; width: 630px; text-align:left" cellspacing="0" cellpadding="0">
<tr>
<td class="blue132 Tdbgcolor1" style="width: 87px">机构名称:</td>
<td class="Tdbgcolor2" colspan="3" style="width: 71px">$$$[InstiName]$$$</td>
<td class="blue132 Tdbgcolor1" style="width: 77px">
类别:</td>
<td class="Tdbgcolor2">$$$[ReportType]$$$</td>
</tr>
<tr>
<td class="blue132 Tdbgcolor1" style="width: 87px">报告时间:</td>
<td colspan="3" align="center" class="Tdbgcolor2" style="width: 71px">$$$[ReportTime]$$$</td>
<td class="blue132 Tdbgcolor1" style="width: 77px">
研究员:</td>
<td class="Tdbgcolor2 y13">$$$[ReportMan]$$$</td>
</tr>
<tr>
<td colspan="6" class="Tdbgcolor2">
<div style="float:right" class="red13"><a href="http://www.cnblogs.com/user/vip/favorPost.aspx?type=myfav&favsort=stock&id=$$$[StocksWareHouseID]$$$" >[收藏此报告]</a></div>
<div class="newsbt" style="width:600px" >$$$[Title]$$$</div>
<div class="newszw" style="text-indent:2em;width:580px">$$$[Reportcontent]$$$</div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
ReportCommonOperation RCO =new ReportCommonOperation();
RCO.createReportCommonHtml(ID);

浙公网安备 33010602011771号