Generating HTML files

Source: Internet
Author: User

First step: Create a mbpage.html page

Step Two: Background generation

public void ProcessRequest (HttpContext context)
{
Context. Response.ContentType = "Text/plain";
String Mbpath = context. Server.MapPath ("mbpage.html");
Encoding code = encoding.getencoding ("gb2312");
StreamReader sr = null;
StreamWriter SW = null;
string str = NULL;

Read
Try
{
sr = new StreamReader (Mbpath, code);
str = Sr. ReadToEnd ();

}
catch (Exception ex)
{
Throw ex;
}
Finally
{
Sr. Close ();
}

Auto-Rename by time, extension can also be modified by itself
String fileName = DateTime.Now.ToString ("YYYYMMDDHHMMSS") + ". htm";
str = str. Replace ("$title $", "111");//Substitute title
str = str. Replace ("$content $", "2222");//replacement content

Generating static files
Try
{
SW = new StreamWriter (context. Server.MapPath ("htm/") + FileName, false, code);
Sw. Write (str);
Sw. Flush ();

}
catch (Exception ex)
{
Throw ex;
}
Finally
{
Sw. Close ();
Context. Response.Write ("Congratulations <a href=htm/" + filename + "target=_blank>" + filename + "</a> has been generated, saved in the HTM folder! ");
}
Context. Response.End ();
}

Generating HTML files

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.