public static string SiteTemplate()//HTML页的模板
{
string str = "";
str += "<HTML>";
str += "<head>";
str += "<title>biaoti</title>";
str += "</head>";
str += "<body>";
str += "biaoti";
str += "<br>";
str += "content<br>";
str += "author";
str += "</body>";
str += "</HTML>";//模版页html代码
return str;
}
public static bool WriteFile(string strText, string strContent, string strAuthor)
{
//string path = HttpContext.Current.Server.MapPath("/htm/");//文件输出目录,如果有这句还会出异常,是未能映射路径"/htm/"
Encoding code = Encoding.GetEncoding("utf-8"); StreamWriter sw = null;
string str = SiteTemplate();//读取模版页面html代码 string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";//静态文件名
// 替换内容
//str = str.Replace("ShowArticle", strText);//这句不知道干什么用的
str = str.Replace("biaoti", strText);
str = str.Replace("content", HttpUtility.HtmlDecode(strContent));
str = str.Replace("author", strAuthor);
// 写文件
try
{
sw = new StreamWriter("E:Hover/htm/" + 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;
}用这段代码生成静态页面以后,打开HTML文件一看,段落格式都没了,怎么解决呀?顺便告诉我怎么结贴给分...汗
{
string str = "";
str += "<HTML>";
str += "<head>";
str += "<title>biaoti</title>";
str += "</head>";
str += "<body>";
str += "biaoti";
str += "<br>";
str += "content<br>";
str += "author";
str += "</body>";
str += "</HTML>";//模版页html代码
return str;
}
public static bool WriteFile(string strText, string strContent, string strAuthor)
{
//string path = HttpContext.Current.Server.MapPath("/htm/");//文件输出目录,如果有这句还会出异常,是未能映射路径"/htm/"
Encoding code = Encoding.GetEncoding("utf-8"); StreamWriter sw = null;
string str = SiteTemplate();//读取模版页面html代码 string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";//静态文件名
// 替换内容
//str = str.Replace("ShowArticle", strText);//这句不知道干什么用的
str = str.Replace("biaoti", strText);
str = str.Replace("content", HttpUtility.HtmlDecode(strContent));
str = str.Replace("author", strAuthor);
// 写文件
try
{
sw = new StreamWriter("E:Hover/htm/" + 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;
}用这段代码生成静态页面以后,打开HTML文件一看,段落格式都没了,怎么解决呀?顺便告诉我怎么结贴给分...汗
说下html代码换行的办法吧 "\n" 是换行
"\t" 是缩进更多转义字符Character
Escape Sequence
'
\'
"
\"
\
\\
警报
\a
退格符
\b
换页符
\f
换行符
\n
回车符
\r
Tab 符
\t
垂直 Tab 符
\v
使用数字指定的Unicode 字符,如\u2000
\u
使用十六进制数指定的Unicode 字符,如\xc8
\x
空值
\0 (zero)
一般我会这样写!
这句是告诉你生成的静态页面放在哪儿,有错误是你的路径不对,或者文件夹没有创建,需要你创建文件夹。还有希望你的模板里有特殊字符。只有特殊字符替换的时候才不会有可能跟你的正文里的东西冲突。你这样问题是很多的。样式乱了你可以用编辑器打开你生成的页面看看,到底是css没有还是标记缺失了。自己仔细的看看就知道了。