public static bool WriteHtml(string[][] replaceSign, string templatePage, string saveHtmlPage, string encodingName)
{
System.Web.UI.Page page = new Page();
//---------------------读html模板页面到stringbuilder对象里----
System.Text.StringBuilder htmltext = new System.Text.StringBuilder();
try
{
System.IO.StreamReader sr = new System.IO.StreamReader(page.Server.MapPath(templatePage.Trim()), System.Text.Encoding.GetEncoding(encodingName));
string line;
while ((line = sr.ReadLine()) != null)
{
line += Environment.NewLine;//加这一行 就好了
htmltext.Append(line);
}
sr.Close();
}
catch
{
System.Web.HttpContext.Current.Response.Write("<script>alert('读取HTML模板 " + templatePage.Trim() + " 出错!');</script>");
}
//----------替换htm模板里的标记为传入的数组
for (int i = 0; i < replaceSign.Length; i++)
{
htmltext.Replace(replaceSign[i][0], replaceSign[i][1]);
}
//----------生成htm文件------------------――
try
{
string tmphtm = page.Server.MapPath(saveHtmlPage);
System.IO.StreamWriter sw = new System.IO.StreamWriter(tmphtm.Trim(), false, System.Text.Encoding.GetEncoding(encodingName));
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
return true;
}
catch
{
System.Web.HttpContext.Current.Response.Write("<script>alert('" + saveHtmlPage.Trim() + " HTML文件生成失败!');</script>");
return false;
}
}`??r*t???bbs.51aspx.com???E±???óm
{
System.Web.UI.Page page = new Page();
//---------------------读html模板页面到stringbuilder对象里----
System.Text.StringBuilder htmltext = new System.Text.StringBuilder();
try
{
System.IO.StreamReader sr = new System.IO.StreamReader(page.Server.MapPath(templatePage.Trim()), System.Text.Encoding.GetEncoding(encodingName));
string line;
while ((line = sr.ReadLine()) != null)
{
line += Environment.NewLine;//加这一行 就好了
htmltext.Append(line);
}
sr.Close();
}
catch
{
System.Web.HttpContext.Current.Response.Write("<script>alert('读取HTML模板 " + templatePage.Trim() + " 出错!');</script>");
}
//----------替换htm模板里的标记为传入的数组
for (int i = 0; i < replaceSign.Length; i++)
{
htmltext.Replace(replaceSign[i][0], replaceSign[i][1]);
}
//----------生成htm文件------------------――
try
{
string tmphtm = page.Server.MapPath(saveHtmlPage);
System.IO.StreamWriter sw = new System.IO.StreamWriter(tmphtm.Trim(), false, System.Text.Encoding.GetEncoding(encodingName));
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
return true;
}
catch
{
System.Web.HttpContext.Current.Response.Write("<script>alert('" + saveHtmlPage.Trim() + " HTML文件生成失败!');</script>");
return false;
}
}`??r*t???bbs.51aspx.com???E±???óm