根据html页面模板动态生成html页面(c#类)
public void WriteFile()
{
//---------------------讀html模板頁(yè)面到stringbuilder對(duì)象里----
StringBuilder htmltext = new StringBuilder();
try
{
string tempath = System.Configuration.ConfigurationManager.AppSettings["HotelReservationTemplate"];
using (StreamReader sr = new StreamReader(Server.MapPath( tempath))) //模板頁(yè)路徑
{
//String line;
//while ((line = sr.ReadLine()) != null)
//{
// htmltext.Append(line);
//}
//sr.Close();
string line = sr.ReadLine();
while (line != null)
{
htmltext.Append(line);
}
sr.Close();
}
}
catch
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "d3", "alert('讀取文件錯(cuò)誤!!')", true);
}
//---------------------給標(biāo)記數(shù)組賦值------------
//----------替換htm里的標(biāo)記為你想加的內(nèi)容
for (int i = 0; i < 13; i++)
{
htmltext.Replace("$htmlformat[" + i + "]", m_format[i]);
}
m_HtmlText = htmltext.ToString();
//----------生成htm文件------------------――
try
{
string tempath = System.Configuration.ConfigurationManager.AppSettings["HotelReservation"];
string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".html";
string newPath = Server.MapPath(tempath) + filename;
//m_NewPath = newPath;
//using (StreamWriter sw = new StreamWriter(newPath, false, System.Text.Encoding.GetEncoding("GB2312"))) //保存地址
//{
// sw.WriteLine(htmltext);
// sw.Flush();
// sw.Close();
//}
}
catch
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "d4", "alert('發(fā)送失敗!!')", true);
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/haowenling/p/5212761.html
總結(jié)
以上是生活随笔為你收集整理的根据html页面模板动态生成html页面(c#类)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: UITextField的属性与程序启动后
- 下一篇: [xUnit]尝试单元测试