asp.net生成静态页面的源码 求asp.net生成静态页面的源码下载地址我邮箱是[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary> /// 生成HTML页 /// </summary> /// <param name="strText">新闻名称</param> /// <param name="strContent">新闻内容</param> /// <param name="strTime">发表时间</param> /// <returns></returns> public bool WriteFile(string strText,string strTime,string strContent) { string path = HttpContext.Current.Server.MapPath("news/"); Encoding code = Encoding.GetEncoding("gb2312"); // 读取模板文件 string temp = HttpContext.Current.Server.MapPath("news/test.htm"); 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(); } string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html"; // 替换内容 // 这时,模板文件已经读入到名称为str的变量中了 str =str.Replace("TitleTitle",strText); //模板页中的ShowArticle str = str.Replace("TimesTimes",strTime); str = str.Replace("MemoMemo",strContent); // 写文件 try { sw = new StreamWriter(path + htmlfilename , false, code); sw.Write(str); sw.Flush(); } catch(Exception ex) { HttpContext.Current.Response.Write(ex.Message); HttpContext.Current.Response.End(); } finally { sw.Close(); } return true; } 其实它的思路很简单,就是先做一个模板TEST.HTM,把新闻页面的样式先做进去,然后把它读取到一个变量中,把里面的新闻标题,内容等到替换掉,然后再写入一个文件. test.htm___________________________________________________________________________<table cellspacing="0" cellpadding="0" width="537" border="0"> <tbody> <tr> <td width="511"> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td width="30"> </td> <td align="center" class="a1"><font color="#cc0000" size="3"><strong> <span id="News_Title">TitleTitle</span></strong></font></td> </tr> </tbody> </table></td> </tr> <tr> <td height="30"> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr class="a3"> <td align="right"> <span id="News_Time">发表日期:TimesTimes</span> </td> </tr> </tbody> </table></td> </tr> <tr> <td valign="top" align="center"> <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" id="dstTable"> <tbody> <tr> <td width="100%" class="a2"> MemoMemo</td> </tr> </tbody> </table></td> </tr> </tbody></table> http://community.csdn.net/Expert/topic/4676/4676923.xml?temp=9.559268E-02 生成单个html不难,但如果大量生成html问题就出来了。生成后如何链接问题就出来了不可能一个一个页面手动生成html,然后连接过去的吗?这样的话工作量岂不是巨大啊如何能够实现循环生成动态链接能提供一下源码的项目文件吗[email protected] 参考一下!!!有的话麻烦多发一封.谢谢[email protected] 我觉得应该直接修改用于缓存的http module object 未定义 如何改变数据库的名称 简单的一小段代码,为什么COOKIES不能添加?????放到你机器上执行一下,肯定也是同样的结果! 关于投票的一些问题 求帮助 语法错误找不出来... “system.select_notice()”: 并非所有的代码路径都返回值 求一输入0~100的正则表达式. WIN7 VS2005 急救!!!! 求高人看看.net能实现这个功能不,能的话必有重谢 各位介绍一下文件上传怎么写啊? 急求Web下的选择文件夹控件,高手求救 vs.net2005怎么才能只生成一个dll文件
/// 生成HTML页
/// </summary>
/// <param name="strText">新闻名称</param>
/// <param name="strContent">新闻内容</param>
/// <param name="strTime">发表时间</param>
/// <returns></returns>
public bool WriteFile(string strText,string strTime,string strContent)
{
string path = HttpContext.Current.Server.MapPath("news/");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("news/test.htm");
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();
}
string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str =str.Replace("TitleTitle",strText); //模板页中的ShowArticle
str = str.Replace("TimesTimes",strTime);
str = str.Replace("MemoMemo",strContent);
// 写文件
try
{
sw = new StreamWriter(path + htmlfilename , false, code);
sw.Write(str);
sw.Flush();
}
catch(Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
return true; }
___________________________________________________________________________<table cellspacing="0" cellpadding="0" width="537" border="0">
<tbody>
<tr>
<td width="511"> <table cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="30"> </td>
<td align="center" class="a1"><font color="#cc0000" size="3"><strong>
<span id="News_Title">TitleTitle</span></strong></font></td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td height="30"> <table cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr class="a3">
<td align="right"> <span id="News_Time">发表日期:TimesTimes</span> </td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td valign="top" align="center"> <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" id="dstTable">
<tbody>
<tr>
<td width="100%" class="a2"> MemoMemo</td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
不可能一个一个页面手动生成html,然后连接过去的吗?这样的话工作量岂不是巨大啊
如何能够实现循环生成动态链接
能提供一下源码的项目文件吗
[email protected]
有的话麻烦多发一封.谢谢
[email protected]