Ideas
1. Use tools such as Dw-Mx to generate html-format templates, add special marks (such as $htmlformat$) where you need to add formats. When dynamically generating files, use code to read this template, then obtain the content input from the foreground, add it to the marking location of this template, generate a new file name and write it to the disk, and then write relevant data to the database after writing it.
2. Use background code to hardcode the Html file, you can use the HtmlTextWriter class to write the html file.
advantage
1. You can create a very complex page. Using the method containing a js file, adding the () method to the js file can add content such as page headers, advertisements, etc. to all pages.
2. Static html files can be built using the Index Server of MS Windows 2000, and search results can be obtained through DataTable. However, the Win2000 Index service cannot find the content of the xml file. If the dual search of database search and Index index are included, this search function will be very powerful.
3. Save the load on the server, and requesting a static html file is much more cost-effective than a aspx file server resource.
shortcoming
Idea 2: If you use hard code, the workload is very large and you need a lot of html code. Debugging is difficult. Moreover, the html style generated using hard-code cannot be modified. If the website changes the style, it must be recoded, which will bring huge workload to the later stage.
Therefore, the first idea is adopted here
Show column code
1. Define()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>
Code:
//-----------------------------------------------------------------------------------------------------------------------------
string[] format=new string[4];//Define an array with the same number of htmlyem tags as the same as the htmlyem tag.
StringBuilder htmltext=new StringBuilder();
try
{
using (StreamReader sr = new StreamReader("Storing the path and page name of the template page"))
{
String line;
while ((line = ()) != null)
{
(line);
}
();
}
}
catch
{
("<Script>alert('Read file error')</Script>");
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
format[0]="background=\"\"";//Background picture
format[1]= "#990099";//Font color
format[2]="150px";//Font size
format[3]= "<marquee> generated template html page</marquee>";//Text description
//--------------Replace the mark in htm to the content you want to add
for(int i=0;i<4;i++)
{
("$htmlformat["+i+"]",format[i]);
}
//-----------------------------------------------------------------------------------------------------------------------------
try
{
using(StreamWriter sw=new StreamWriter("Storing path and page name", false,("GB2312")))
{
(htmltext);
();
();
}
}
catch
{
("The file could not be wirte:");
}
summary
This method can easily generate html files. The program uses loop replacement, so it is very fast for templates that need to replace a large number of elements.