Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > C#/.NET技巧

asp.net实现生成静态页并添加链接的方法

来源:中文源码网    浏览:170 次    日期:2024-05-18 10:48:35
【下载文档:  asp.net实现生成静态页并添加链接的方法.txt 】


asp.net实现生成静态页并添加链接的方法
本文以实例讲解了asp.net实现生成静态页并添加链接的方法,非常实用的功能,通过本实例可以加深读者对于asp.net下文件操作的认识。
1.创建一个静态网页模板



模板网页








$htmlformat[1]


$htmlformat[4]




2.在asp.net网页后台代码中替换模板html页中的标记符
protected void Button1_Click(object sender, EventArgs e)
{
string[] format = new string[5];//定义和htmlyem标记数目一致的数组
StringBuilder htmltext = new StringBuilder();
string templatePath = Server.MapPath("~/html/Template.html");
StreamReader sr = new StreamReader(templatePath);
String line;
while ((line = sr.ReadLine()) != null)
{
htmltext.Append(line);
}
sr.Close();
//---------------------给标记数组赋值------------
format[0] = "background=\"bg.jpg\"";//背景图片
format[1] = TB_Title.Text;
format[2] = "#990099"; //字体颜色
format[3] = "60px";//文字大小
format[4] = TB_Content.Text;
//----------替换htm里的标记为你想加的内容
for (int i = 0; i < 5; i++)
{
htmltext.Replace("$htmlformat[" + i + "]", format[i]);
}
//----------生成htm文件------------------――
string newfile = Server.MapPath("~/html/"+TB_Title.Text+".html");
StreamWriter sw = new StreamWriter(newfile, false, System.Text.Encoding.GetEncoding("GB2312"));
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
string newhref="html/" rel="external nofollow" +TB_Title.Text+".html";
Response.Write("" + TB_Title.Text + "");
}

相关内容