Ideas
1. Use tools such as DW-MX to generate HTML-formatted templates, add special tags (such as $htmlformat$) where needed, and dynamically generate files using code to read the template, and then get the foreground input to add to the tag location of the template, Writes the new file name to the disk and writes the relevant data to the database after it is written.
2. Using background code to hard-code HTML files, you can use the HtmlTextWriter class to write HTML files.
Advantages
1. Can be a very complex page, using the method containing JS files, in the JS file to add document.write () method can be added to all pages, such as page header, advertising and other content.
2. Static HTML files Use MS Windows2000 's Index server to create Full-text search engines, using asp.net to get search results in a DataTable. The Win2000 Index Service was unable to find the contents of the XML file. If you include a database search and index index double lookup, then this search function will be very powerful.
3. Save the load on the server and request a static HTML file to save a lot more than an ASPX file server resource.
Disadvantages
Idea two: If the hard coded way, the workload is very large, need a lot of HTML code. Debugging difficult. And the HTML style generated with hard coding cannot be modified, and if the site is replaced, it must be coded to bring a huge workload to the later stage.
So here's the first way to take it.
Column Code
1. Define (template.htm) HTML Template page
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body >
<table $htmlformat[0] height="100%" border="0" width="100%" cellpadding="10" cellspacing="0" bgcolor="#eeeeee" style="border:1px solid #000000">
<tr>
<td width="100%" valign="middle" align="left">
<span style="color: $htmlformat[1];font-size: $htmlformat[2]">$htmlformat[3]</span>
</td>
</tr>
</table>
</body>
</html>
2.asp.net Code:
---------------------read the HTML template page to the StringBuilder object----
String[] Format=new string[4];//defines an array with a consistent number of Htmlyem tags
StringBuilder htmltext=new StringBuilder ();
Try
{
using (StreamReader sr = new StreamReader ("path and page name for Template page"))
{
String Line;
while (line = Sr. ReadLine ())!= null)
{
HTMLText. Append (line);
}
Sr. Close ();
}
}
Catch
{
Response.Write ("<Script> alert (' Read file error ') </Script>");
}
---------------------assign a value to an array of tokens------------
format[0]= "background=\" bg.jpg\ "";//Background picture
Format[1]= "#990099";//Font Color
Format[2]= "150px";//font size
format[3]= "<marquee> generated template HTML page </marquee>";//Text description
----------Replace the tags in htm for what you want to add
for (int i=0;i<4;i++)
{
HTMLText. Replace ("$htmlformat [" +i+ "]", format[i]);
}
----------generate HTM file-------------------
Try
{
Using (StreamWriter Sw=new StreamWriter ("Store path and page name", False,system.text.encoding.getencoding ("GB2312"))
{
Sw. WriteLine (HTMLText);
Sw. Flush ();
Sw. Close ();
}
}
Catch
{
Response.Write ("The file could not be wirte:");
}
Summary
This method makes it easy to generate HTML files. The program uses a circular replacement, so the template that needs to replace a large number of elements is fast.