.net2.0怎么生成静态页面?? .net2.0怎么生成静态页面??请把文件发到发过来的时候请注明您CSDN里的用户名~~用得上100分送上. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://download.csdn.net/source/293578 using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.IO;using System.Xml;using System.Text;/// <summary>/// CreatHtml 的摘要说明/// </summary>public class CreatHtml{ public CreatHtml() { // // TODO: 在此处添加构造函数逻辑 // } //生成HTML页 public static bool WriteFile(string strText, string strContent, string strAuthor) { string path = HttpContext.Current.Server.MapPath("news"); Encoding code = Encoding.GetEncoding("gb2312"); // 读取模板文件 string temp = HttpContext.Current.Server.MapPath("newsTemplate/Text.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(); } string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"; // 替换内容 // 这时,模板文件已经读入到名称为str的变量中了 str = str.Replace("ShowArticle", strText); //模板页中的ShowArticle str = str.Replace("biaoti", strText); str = str.Replace("content", strContent); str = str.Replace("author", strAuthor); // 写文件 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; }} sr = new StreamReader(temp, code); str = sr.ReadToEnd(); // 读取文件 摸板页里面定义那几个标签就可以了。自己试一下嘛 aweicd0395 给你发了邮件~~请给我回邮件.马上结分 if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString))) { Response.Write("添加成功"); } else { Response.Write("生成HTML出错!"); } 这个有错误 public static bool WriteFile(string strText, string strContent, string strAuthor) 这里是要传三个什么值过来??? 看看孟老大滴帖子吧在ASP.NET 2.0中直接得到本页面生成的HTML代码不过俺后来又扩展了一下,需两个参数 requestUri 和 staticFilePath,这样放到俺滴扩展库里作为通用方法,哈 其实我们要静态的是做什么了,就是为了SEO,那么我们还有些内容是要动态怎么办了,所以不能生成静态就是可以,统计啊,相关评论啊都可以用动态的做,这个就叫动静结合吧,看看我的网,查看HTML代码可能有你想要的,www.jobdll.com 新闻栏目,www.jobdll.com/user/gt 这个也是的BLOG /// <summary> /// 生成HTML页 /// </summary> /// <param name="newsID">新闻唯一编号(统计用)</param> /// <param name="title">新闻名称</param> /// <param name="content">新闻内容</param> /// <param name="addTime">发表时间</param> /// <param name="filePath">要保存的路径</param> /// <param name="stencilPath">模版页路径及文件名称</param> /// <returns></returns> public static void CreateHtmlFile(string newsID,string title,string addTime,string content,string filePath,string stencilPath) { string path = System.Web.HttpContext.Current.Server.MapPath(filePath); Encoding code = Encoding.GetEncoding("gb2312"); System.IO.DirectoryInfo dir=new System.IO.DirectoryInfo(path.Substring(0,path.LastIndexOf("\\"))); //判断文件夹否存在,不存在则创建 if(!dir.Exists) { dir.Create(); } // 读取模板文件 string temp = System.Web.HttpContext.Current.Server.MapPath(stencilPath); StreamReader sr=null; StreamWriter sw=null; string str=""; try { sr = new StreamReader(temp, code); str = sr.ReadToEnd(); // 读取文件 sr.Close(); } catch(Exception exp) { System.Web.HttpContext.Current.Response.Write(exp.Message); System.Web.HttpContext.Current.Response.End(); sr.Close(); } //string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".htm"; // 替换模版中的内容 str = str.Replace("[newsid]",newsID); //替换新闻ID str = str.Replace("[title]",title); //替换新闻标题 str = str.Replace("[addtime]",addTime); //替换新闻更新时间 str = str.Replace("[content]",content); //替换新闻内容 // 写文件 try { sw = new StreamWriter(path, false, code); sw.Write(str); sw.Flush(); } catch(Exception ex) { System.Web.HttpContext.Current.Response.Write(ex.Message); System.Web.HttpContext.Current.Response.End(); } finally { sw.Close(); } }楼主还不明白就加我Q82161001 http://blog.csdn.net/Samanthaqu/archive/2007/12/04/1915881.aspx其中:string fileName = Request.Form["ddlDate"] + ".htm";Response.WriteFile(Server.MapPath("~/ProjectHome/Upload/" + fileName));Response.End(); ASP.NET listview 控件宽度的设置 看看我的帖子吧 。急死我咧~~~图片路径问题 关于Application.lock()的触发条件 新手的问题…… ISAPI扩展 和 ISAPI筛选器 各是什么意思,它们的区别是什么? 关于数组参数的小问题 我在使用datagril自创建列时,如何使某一特定列位于datagril的末列? Asp.net如何做类似WinForm中的选项卡??? 关于Devexpress的Callback控件的问题 关于网站注册部分的问题? GridView的高手中的高手,大师人物级别的来看看... 没有分了,但请各位热心的进来帮帮忙
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Text;/// <summary>
/// CreatHtml 的摘要说明
/// </summary>
public class CreatHtml
{
public CreatHtml()
{
//
// TODO: 在此处添加构造函数逻辑
//
} //生成HTML页
public static bool WriteFile(string strText, string strContent, string strAuthor)
{
string path = HttpContext.Current.Server.MapPath("news");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("newsTemplate/Text.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();
}
string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("ShowArticle", strText); //模板页中的ShowArticle
str = str.Replace("biaoti", strText);
str = str.Replace("content", strContent);
str = str.Replace("author", strAuthor);
// 写文件
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;
}
}
str = sr.ReadToEnd(); // 读取文件
摸板页里面定义那几个标签就可以了。自己试一下嘛
{
Response.Write("添加成功");
}
else
{
Response.Write("生成HTML出错!");
}
这个有错误
这里是要传三个什么值过来???
在ASP.NET 2.0中直接得到本页面生成的HTML代码不过俺后来又扩展了一下,需两个参数 requestUri 和 staticFilePath,
这样放到俺滴扩展库里作为通用方法,哈
/// 生成HTML页
/// </summary>
/// <param name="newsID">新闻唯一编号(统计用)</param>
/// <param name="title">新闻名称</param>
/// <param name="content">新闻内容</param>
/// <param name="addTime">发表时间</param>
/// <param name="filePath">要保存的路径</param>
/// <param name="stencilPath">模版页路径及文件名称</param>
/// <returns></returns>
public static void CreateHtmlFile(string newsID,string title,string addTime,string content,string filePath,string stencilPath)
{
string path = System.Web.HttpContext.Current.Server.MapPath(filePath);
Encoding code = Encoding.GetEncoding("gb2312");
System.IO.DirectoryInfo dir=new System.IO.DirectoryInfo(path.Substring(0,path.LastIndexOf("\\")));
//判断文件夹否存在,不存在则创建
if(!dir.Exists)
{
dir.Create();
}
// 读取模板文件
string temp = System.Web.HttpContext.Current.Server.MapPath(stencilPath);
StreamReader sr=null;
StreamWriter sw=null;
string str="";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
sr.Close();
}
catch(Exception exp)
{
System.Web.HttpContext.Current.Response.Write(exp.Message);
System.Web.HttpContext.Current.Response.End();
sr.Close();
}
//string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".htm"; // 替换模版中的内容
str = str.Replace("[newsid]",newsID); //替换新闻ID
str = str.Replace("[title]",title); //替换新闻标题
str = str.Replace("[addtime]",addTime); //替换新闻更新时间
str = str.Replace("[content]",content); //替换新闻内容
// 写文件
try
{
sw = new StreamWriter(path, false, code);
sw.Write(str);
sw.Flush();
}
catch(Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex.Message);
System.Web.HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
}楼主还不明白就加我Q82161001
string fileName = Request.Form["ddlDate"] + ".htm";
Response.WriteFile(Server.MapPath("~/ProjectHome/Upload/" + fileName));
Response.End();