Environment: Microsoft .NET Framework SDK V1.1
OS: Windows Server 2003 Chinese version
ASP.NET Generate Static HTML Page
Generate the FileSystemObject object to generate a static page in the ASP!
This type of operation is involved in .NET is System.io
The following is the program code Note: This code is non-original! Refer to others code
CODE:
/ / Generate HTML Page
Public Static Bool Writefile (String StRTEXT, STRING Strauthor)
{
String path = httpContext.current.server.mappath ("/ news /");
Encoding code = encoding.getencoding ("GB2312");
// read the template file
String temp = httpContext.current.server.mappath ("/ news / text.html");
StreamReader SR = NULL;
Streamwriter SW = NULL;
String str = "";
Try
{
SR = New StreamReader (TEMP, CODE);
Str = sr.readToEnd (); // Read file
}
Catch (Exception Exp)
{
HttpContext.current.Response.write (Exp.MESSAGE);
HttpContext.current.Response.end ();
sr.close ();
}
String htmlfilename = datetime.now.toString ("YYYYMMDDHHMMSS") ". HTML";
// Replace content
// At this time, the template file has been read into the variable named STR.
Str = str.replace ("ShowArticle", Strtext); // SHOGTICLE in the template page
Str = str.replace ("biaoti", strText);
Str = str.replace ("Content", strcontent);
Str = str.replace ("author", strauthor);
// write file
Try
{
SW = New streamwriter (Path HTMLFileName, False, Code);
SW.WRITE (STR);
Sw.flush ();
}
Catch (Exception EX)
{
HttpContext.current.Response.write (ex.Message);
HttpContext.current.Response.end ();
}
Finally
{
SW.CLOSE ();
}
Return True;
This function is placed in the conn.cs base class.
Quote in the code to add news Note: Engineering name HOVER
IF (Hover.Conn.writefileTHis.title.Text.Tostring), this.content.text.tostring, this.author.text.tostring))))))))
{
Response.write ("Add success");
}
Else
{
Response.write ("Generate HTML Error!");
}
Template page Text.html code
CODE:
Biaoti
Content
Author
body>
Html>
Biaoti
Content
Author
body>
Html>
When prompted to add a success, the HTML file named at the current time will be written directly! Only a few parameters passed directly into the HTML file, and you need to add the database before practical application, and then write to the HTML file.