// The source code replaces the feature characters in the template.
String Mbpath = Server. mappath ( " Template.html " );
Encoding code = Encoding. getencoding ( " Gb2312 " );
Streamreader SR = Null ;
Streamwriter SW = Null ;
String Str = Null ;
// Read
try
{< br> Sr = New streamreader (mbpath, code);
STR = Sr. readtoend ();
}
Catch (Exception ex)
{
Throw Ex;
}
Finally
{
Sr. Close ();
}
// Automatically rename by time, and the extension can also be modified by yourself
String Filename = Datetime. Now. tostring ( " Yyyymmddhhmmss " ) + " . Aspx " ;
Str = Str. Replace ( " $ Title $ " , " 123 asdfasf " ); // Replace title
Str = Str. Replace ( " $ Content $ " , " Asdf2354234 " ); // Replace content
// Generate static files
Try
{
SW = New Streamwriter (server. mappath ( " Htm/ " ) + Filename, False , Code );
Sw. Write (STR );
Sw. Flush ();
}
Catch (Exception ex)
{
Throw Ex;
}
Finally
{
Sw. Close ();
Response. Write ( " Congratulations <a href = htm/ " + Filename + " Target = _ blank> " + Filename + " </A> generated and saved in the HTM folder! " );
}
Template.html <! 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 $ generate a static page demo </ Title >
< Style Type = "Text/CSS" >
<! --
. Style1 {
Font-size : 16px ;
Font-weight : Bold ;
}
-->
</ Style >
</ Head >
< Body >
< BR />
< BR />
< Table Width = "100%" Border = "0" Bgcolor = "#339900" >
< Tr >
< TD Height = "34" Align = "Center" Bgcolor = "# Ffffff" > < Span Class = "Style1" > $ Title $ </ Span > </ TD >
</ Tr >
< Tr >
< TD Height = "42" Bgcolor = "# Ffffff" > < BR />
< BR />
Content: $ content $ </ TD >
</ Tr >
</ Table >
</Body>
</Html>