Asp.net generates HTML static pages

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 of createhtml  ///  Asp.net generates HTML static pages  ///  Call method:  ///  New createhtml (). nei_create ("http: // localhost: 4032/new5mdn/default. aspx", "default.htm ");  /// </Summary>  Public class  Createhtml : System. Web. UI. Page { Public Createhtml (){}/// <Summary> ///  Generate a static page under this project  /// </Summary> /// <Param name = "strurl">  Request URL  </Param> /// <Param name = "strrelpath">  The created path and file name. The 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 = Null ; // Obtain the static html of aspx  Try { If ( File . Exists (strfilepage )){ File . Delete (strfilepage);} Sw = New  Streamwriter (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 = New  Streamreader (Respstream, system. Text. Encoding . Getencoding ( "Gb2312" ));String Strtemp = reader. readtoend (); RegEx R1 = New  RegEx ( "<Input type = \" Hidden \ "name = \" _ eventtarget \ ". */>" , Regexoptions . Ignorecase ); RegEx R2 = New  RegEx ( "<Input type = \" Hidden \ "name = \" _ eventargument \ ". */>" , Regexoptions . Ignorecase );RegEx R3 = New  RegEx ( "<Input type = \" Hidden \ "name = \" _ viewstate \ ". */>" , Regexoptions . Ignorecase ); RegEx R4 = New  RegEx ( "<Form. * id = \" form1 \ ">" , Regexoptions . Ignorecase ); RegEx R5 = New  RegEx ( "</Form>" ); RegEx R6 = New  RegEx ( "<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 );} Catch ( Exception Ex ){ Httpcontext . Current. response. Write (ex. Message ); Httpcontext . Current. response. End (); Return false ; // Generate an error } Finally {Sw. Flush (); Sw. Close (); Sw =Null ;}} /// <Summary> ///  Generate a static page, which is not in this project  /// </Summary> /// <Param name = "strurl">  Request URL  </Param> /// <Param name = "strrelpath">  Path and file name. The path is an absolute path.  </Param>  Public bool Wai_create ( String Strurl, String Strrelpath, String Filename ){String Strfilepage; strfilepage = strrelpath + "\\" + Filename; Streamwriter Sw = Null ; // Obtain the static html of aspx  Try { If (! Directory . Exists (strrelpath )){ Directory . Createdirectory (strrelpath );} If ( File . Exists (strfilepage )){ File . Delete (strfilepage);} Sw = New  Streamwriter (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 = New  RegEx ( "<Input type = \" Hidden \ "name = \" _ eventtarget \ ". */>" ,Regexoptions . Ignorecase ); RegEx R2 = New  RegEx ( "<Input type = \" Hidden \ "name = \" _ eventargument \ ". */>" , Regexoptions . Ignorecase ); RegEx R3 = New  RegEx ( "<Input type = \" Hidden \ "name = \" _ viewstate \ ". */>" , Regexoptions . Ignorecase );RegEx R4 = New  RegEx ( "<Form. * id = \" form1 \ ">" , Regexoptions . Ignorecase ); RegEx R5 = New  RegEx ( "</Form>" ); RegEx R6 = New  RegEx ( "<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 );} Catch ( Exception Ex ){Httpcontext . Current. response. Write (ex. Message ); Httpcontext . Current. response. End (); Return false ; // Generate an error } Finally {Sw. Flush (); Sw. Close (); Sw = Null ;} Return true ;} Public void Filepicdelete ( String Path) {system. Io. Fileinfo File =New System. Io. Fileinfo (); If (File. exists) file. Delete ();}}

Related Article

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.