• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    asp.net实现生成静态页并添加链接的方法

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

    1.创建一个静态网页模板

    !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    html xmlns="http://www.w3.org/1999/xhtml">
    head>
    title>模板网页/title>
    meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    /head>
    body>
    table $htmlformat[0] height="100%" border="0" width="100%" cellpadding="10" cellspacing="0" gcolor="#eeeeee" style="border:1px solid #000000">
    tr>
    td width="100%" valign="middle" align="left">
    h1>$htmlformat[1]/h1>
    div style="color: $htmlformat[2];font-size: $htmlformat[3]">$htmlformat[4]/div>
    /td>
    /tr>
    /table>
    /body>
    /html>
    
    

    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("a href=\"" + newhref + "\">" + TB_Title.Text + "/a>");
    }
    您可能感兴趣的文章:
    • asp.net中MVC借助Iframe实现无刷新上传文件实例
    • asp.net在iframe中弹出信息并执行跳转问题探讨
    • ASP.NET页面借助IFrame提交表单数据所遇到问题的解决方法分享
    • asp.net 文件上传与刷新与asp.net页面与iframe之间的数据传输
    • ASP.NET中使用IFRAME建立类Modal窗口
    • asp.net省市三级联动的DropDownList+Ajax的三种框架(aspnet/Jquery/ExtJs)示例
    • asp.net 学习之路 项目整体框架简单的搭建
    • asp.net GridView中超链接的使用(带参数)
    • ASP.NET 链接 Access 数据库路径问题最终解决方案
    • ASP.NET中iframe框架点击左边页面链接 右边显示链接页面内容
    上一篇:ASP.NET中IsPostBack用法详解
    下一篇:ASP.NET中常见文件类型、扩展名、存放位置及用途总结
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

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