ASP. HTML static page generation

Source: Internet
Author: User

Using System;Using System.Data;Using System.Configuration;Using System.Web;Using System.Web.Security;Using System.Web.UI;Using System.Web.UI.WebControls;Using System.Web.UI.WebControls.WebParts;Using System.Web.UI.HtmlControls;Using System.Text.RegularExpressions;Using System.IO;<summary>///Summary description of Createhtml///ASP. HTML static page generation///Call Method:///New Createhtml (). Nei_create ("http://localhost:4032/new5mdn/default.aspx", "default.htm");</summary>public classCreateHtml:System.Web.UI.page{Public createhtml () {}<summary>//Generate a static page, the build location is under this project</summary>//<param name= "strURL" >The requested URL</param>//<param name= "Strrelpath" >Path and file name created, path is relative path</param>//<returns></returns>public bool Nei_create (String strURL,String Strrelpath) {String Strfilepage; Strfilepage =HttpContext.Current.Server.MapPath (Strfilepage);StreamWriter SW =NullGet the static HTML for ASPXtry {if (File.exists (Strfilepage)) {File.delete (Strfilepage); } SW =NewStreamWriter (Strfilepage,False, System.Text.Encoding.GetEncoding ("gb2312")); System.Net.WebRequest WReq = System.Net.WebRequest.Create (strURL); System.Net.WebResponse wresp = Wreq.getrequeststream (); System.IO.Stream Respstream = Wresp.getresponsestream (); System.IO.StreamReader reader =NewStreamReader (Respstream, System.Text.Encoding.GetEncoding ("gb2312"));String strtemp = reader. ReadToEnd ();Regex R1 =NewRegex ("<input type=\" hidden\ "name=\" __eventtarget\ ".*/>",Regexoptions.ignorecase);Regex r2 =NewRegex ("<input type=\" hidden\ "name=\" __eventargument\ ".*/>",Regexoptions.ignorecase);Regex R3 =NewRegex ("<input type=\" hidden\ "name=\" __viewstate\ ".*/>",Regexoptions.ignorecase);Regex R4 =NewRegex ("<form. *id=\" form1\ ">",Regexoptions.ignorecase);Regex R5 =NewRegex ("</form>");Regex R6 =NewRegex ("<input type=\" hidden\ "name=\" __eventvalidation\ ".*/>",Regexoptions.ignorecase); strtemp = R1. Replace (strtemp,""); strtemp = R2. Replace (strtemp,""); strtemp = R3. Replace (strtemp,""); strtemp = R4. Replace (strtemp,""); strtemp = R5. Replace (strtemp,""); strtemp = R6. Replace (strtemp,""); Sw. Write (strtemp); }CatchException ex) {HttpContext.Current.Response.Write (ex. Message);HttpContext.Current.Response.End ();return false;Build to Error}finally {SW. Flush (); Sw. Close (); SW =Null } }<summary>//Generate a static page, the build location is not under this item</summary>//<param name= "strURL" >The requested URL</param>//<param name= "Strrelpath" >Created path and file name, path is absolute path</param>public bool Wai_create (String strURL,String Strrelpath,string filename) {String Strfilepage; Strfilepage = Strrelpath +"\ \" + filename;StreamWriter SW =NullGet the static HTML for ASPXtry {if (!Directory.Exists (Strrelpath)) {Directory.CreateDirectory (Strrelpath); }if (File.exists (Strfilepage)) {File.delete (Strfilepage); } SW =NewStreamWriter (Strfilepage,False, System.Text.Encoding.GetEncoding ("gb2312")); System.Net.WebRequest WReq = System.Net.WebRequest.Create (strURL); System.Net.WebResponse wresp = Wreq.getresponse (); System.IO.Stream Respstream = Wresp.getresponsestream (); System.IO.StreamReader reader =New System.IO.StreamReader (Respstream, System.Text.Encoding.GetEncoding ("gb2312"));String strtemp = reader. ReadToEnd ();Regex R1 =NewRegex ("<input type=\" hidden\ "name=\" __eventtarget\ ".*/>",Regexoptions.ignorecase);Regex r2 =NewRegex ("<input type=\" hidden\ "name=\" __eventargument\ ".*/>",Regexoptions.ignorecase);Regex R3 =NewRegex ("<input type=\" hidden\ "name=\" __viewstate\ ".*/>",Regexoptions.ignorecase);Regex R4 =NewRegex ("<form. *id=\" form1\ ">",Regexoptions.ignorecase);Regex R5 =NewRegex ("</form>");Regex R6 =NewRegex ("<input type=\" hidden\ "name=\" __eventvalidation\ ".*/>",Regexoptions.ignorecase); strtemp = R1. Replace (strtemp,""); strtemp = R2. Replace (strtemp,""); strtemp = R3. Replace (strtemp,""); strtemp = R4. Replace (strtemp,""); strtemp = R5. Replace (strtemp,catch (exception ex) {httpcontext.current.response.end (); return false; //Build to Error} finally {sw. Flush (); Sw. Close (); SW = null;} return true;} public void Filepicdelete (string path) {System.io.fileinfo file =  FileInfo (); if (file. Exists) file. Delete (); }} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.