C#生成静态页面的方法
来源:互联网 发布:淘宝卖家可以删差评吗 编辑:程序博客网 时间:2024/06/05 20:02
C#生成静态页面的方法
以下是C#生成静态页面的一种方法
private bool CreateHl(string strtext, string strcontent, string author)
{
string yearstring = DateTime.Now.Year.ToString();
string monthstring = DateTime.Now.Month.ToString();
string daystring = DateTime.Now.Day.ToString();
string filename = yearstring + monthstring + daystring + DateTime.Now.Millisecond.ToString() + ".html";
Directory.CreateDirectory(Server.MapPath("" + yearstring + "//" + monthstring + "//" + daystring + ""));
Encoding code = Encoding.GetEncoding("gb2312");
string temp = Server.MapPath("test.htm");
Response.Write(temp);
//Response.End();
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd();
}
catch (Exception exp)
{
Response.Write(exp.Message);
Response.End();
sr.Close();
}
strcontent += strcontent.Replace("\n", "<br>");
strcontent += strcontent.Replace("\r", "<br>");
str = str.Replace("{pagetitle}", strtext);
str = str.Replace("{title}", strtext);
str = str.Replace("{content}", strcontent);
str = str.Replace("{author}", author);
try
{
//sw=new StreamWriter(str,code);
// sw.WriteLine
sw = new StreamWriter(Server.MapPath("" + yearstring + "//" + monthstring + "//" + daystring + "//" + filename + ""), false, code);
//sw.Write;
sw.Write(str);
sw.Flush();
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
msg.Text = filename;
return true;
}
以下是用法protected void Button2_Click(object sender, EventArgs e)
{
string title = txttitle.Text;
string content = txtcontent.Text;
string zuozhe = txtzuzhe.Text;
bool sc;
sc = CreateHl(title, content, zuozhe);
if (sc)
{
Response.Write("HTML生成成功!");
}
else
{
Response.Write("HTML生成失败!");
}
}
- C#生成静态页面的方法
- 生成静态页面的方法
- 生成静态页面的方法
- 生成静态页面的方法
- 生成静态页面的方法
- c#生成静态页面
- c# 生成静态页面
- C# 生成静态页面的分页程序
- 生成静态页面的c#类
- 静态页面生成方法
- 生成静态页面方法
- 生成静态页面方法
- 生成静态页面的方法总结
- [收藏]生成静态页面的方法
- ASP生成静态页面的方法
- ASP生成静态页面的方法
- ASP生成静态页面的方法
- ASP生成静态页面的方法
- linux GCC参数详解
- 网卡驱动:数据包发送的流控机制-netif_start_queue/netif_wake_queue/netif_stop_queue
- asp.net几种submit及参数获取方式
- 错误14274:无法添加、更新或删除从msx服务器上发起的作业(或其步骤或调度)
- Android 客户端与ssh 服务端通信 以对象的形式相互传 (一) 客户端向服务端发送对象
- C#生成静态页面的方法
- 筛法求素数
- 使用删除回收站的程序还原回收站
- 一段H264数据的分析
- mongodb 模糊查询
- onItemSelected在纯触摸屏的手机上是没有效果
- __stdcall 和 __cdecl 的区别
- tortoiseSVN在使用中因为网络断线或者手动在更新中取消而锁定目录的处理办法
- Android.mk 杂乱分析