国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.net生成htm靜態(tài)文件的兩種途徑

2024-07-10 13:08:28
字體:
供稿:網(wǎng)友


//51aspx.com生成靜態(tài)頁演示文件,轉(zhuǎn)載請保留該信息
  2    public partial class _default : system.web.ui.page
  3    ...{
  4        protected void page_load(object sender, eventargs e)
  5        ...{
  6          
  7        }
  8
  9        //根據(jù)模板生成,保持在html文件夾中(部分源碼搜集于網(wǎng)絡(luò))
 10        protected void button1_click(object sender, eventargs e)
 11        ...{
 12            //源碼是替換掉模板中的特征字符
 13
 14            string mbpath =server.mappath("template.htm");
 15            encoding code = encoding.getencoding("gb2312");
 16            streamreader sr = null;
 17            streamwriter sw = null;
 18            string str = null;
 19
 20            //讀取
 21            try
 22            ...{
 23                sr = new streamreader(mbpath, code);
 24                str = sr.readtoend();
 25
 26            }
 27            catch (exception ex)
 28            ...{
 29                throw ex;
 30            }
 31            finally
 32            ...{
 33                sr.close();
 34            }
 35
 36            //根據(jù)時間自動重命名,擴展名也可以自行修改
 37            string filename = datetime.now.tostring("yyyymmddhhmmss") + ".htm";
 38            str = str.replace("$title$", txttitle.text);//替換title
 39            str = str.replace("$content$", txtcontent.text);//替換content
 40
 41            //生成靜態(tài)文件
 42            try
 43            ...{
 44                sw = new streamwriter(server.mappath("htm/") + filename, false, code);
 45                sw.write(str);
 46                sw.flush();
 47
 48            }
 49            catch (exception ex)
 50            ...{
 51                throw ex;
 52            }
 53            finally
 54            ...{
 55                sw.close();
 56                response.write("恭喜<a href=htm/"+filename+" target=_blank>"+filename+"</a>已經(jīng)生成,保存在htm文件夾下!");
 57            }
 58
 59
 60        }
 61
 62
 63        //根據(jù)url地址生成靜態(tài)頁保持
 64        protected void button2_click(object sender, eventargs e)
 65        ...{
 66            encoding code = encoding.getencoding("utf-8");
 67            streamreader sr = null;
 68            streamwriter sw = null;
 69            string str = null;
 70
 71            //讀取遠程路徑
 72            webrequest temp = webrequest.create(txturl.text.trim());
 73            webresponse mytemp = temp.getresponse();
 74            sr = new streamreader(mytemp.getresponsestream(), code);
 75            //讀取
 76            try
 77            ...{
 78                sr = new streamreader(mytemp.getresponsestream(), code);
 79                str = sr.readtoend();
 80
 81            }
 82            catch (exception ex)
 83            ...{
 84                throw ex;
 85            }
 86            finally
 87            ...{
 88                sr.close();
 89            }
 90            string filename = datetime.now.tostring("yyyymmddhhmmss") + ".htm";
 91
 92            //寫入
 93            try
 94            ...{
 95                sw = new streamwriter(server.mappath("htm/") + filename, false, code);
 96                sw.write(str);
 97                sw.flush();
 98
 99            }
100            catch (exception ex)
101            ...{
102                throw ex;
103            }
104            finally
105            ...{
106                sw.close();
107                response.write("恭喜<a href=htm/" + filename + " target=_blank>" + filename + "</a>已經(jīng)生成,保存在htm文件夾下!");
108            }
109
110        }
111    }
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 米泉市| 池州市| 鄂托克旗| 九龙城区| 广饶县| 漳平市| 南澳县| 栾川县| 东丽区| 同仁县| 确山县| 新河县| 连山| 河南省| 四会市| 吉隆县| 南昌市| 雷波县| 宝应县| 闵行区| 平乡县| 仁寿县| 松滋市| 梁山县| 娄烦县| 梅州市| 香格里拉县| 大石桥市| 宁波市| 千阳县| 江都市| 恩施市| 商城县| 宁强县| 合川市| 永胜县| 南昌县| 始兴县| 布拖县| 龙泉市| 福清市|