In order to reduce the burden on the server in the news system. Sometimes you need to put the database content is not dynamically read,
Instead, it is a static web page.
The following is written HTML. Update HTML and delete the HTML code.
Conn.cs in the project is a class library for public calls. (Look at the forum Access version of Dream Ling.
)
/ / Generate HTML Page
Public Static Bool Writefile (String StRTEXT, STRING Strauthor, String FileName)
{
String yy = datetime.now.tostring ("yyyy");
String DD = DATETIME.NOW.TOSTRING ("DD");
String mm = datetime.now.tostring ("mm");
String path = httpContext.current.server.mappath ("/ news /" yy.tostring () "/" mm.toString () "/" DD.TOSTOSTRING () "/");
String addtime = datetime.now.tostring ();
Encoding code = encoding.getencoding ("GB2312");
// read the template file
String temp = httpContext.current.server.mappath ("/ news / template / template.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 ("hhmmss") ". HTML";
// Replace content
// At this time, the template file has been read into the variable named STR.
Str = str.replace ("$ TITLE $", Strtext);
Str = str.replace ("$ filename $", filename);
Str = str.replace ("$ Content $", strcontent);
Str = str.replace ("$ author $", strauthor);
Str = str.replace ("$ addtime $", addtime;
// write file
IF (! system.io.directory.exists (pat))
{
System.io.directory.createdIRectory (PATH);
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;
}
Else
{
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 ();
sr.close ();
}
Return True;
}
}
/ / Modify the HTML page
Public Static Bool Modifyfile (String StRTEXT, STRING STRING, STRING HTMLFILENAME)
{
Encoding code = encoding.getencoding ("GB2312");
String path = httpContext.current.server.mappath ("/ news /" htmlfilename);
// read the template file
String temp = httpContext.current.server.mappath ("/ news / template / template.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 addtime = datetime.now.tostring ();
// Replace content
// At this time, the template file has been read into the variable named STR.
Str = str.replace ("$ TITLE $", Strtext);
Str = str.replace ("$ Content $", strcontent);
Str = str.replace ("$ author $", strauthor);
Str = str.replace ("$ addtime $", addtime;
// write file
Try
{
SW = New streamwriter (Path, False, Code);
SW.WRITE (STR);
Sw.flush ();
}
Catch (Exception EX)
{
HttpContext.current.Response.write (ex.Message);
HttpContext.current.Response.end ();
}
Finally
{
SW.CLOSE ();
sr.close ();
}
Return True;
}
// Delete HTML
Public Static Void Delete (String HTMLFileName)
{
String path = httpContext.current.server.mappath ("/ news /" htmlfilename); TRY
{
File.delete (path);
}
Catch (Exception EX)
{
HttpContext.current.Response.write (ex.Message);
}
} About generation html pages, see ASP.NET to generate static HTML pages! Here you will not say. How to generate a static HTML page how to achieve click rate. This is a problem. It seems that the ASP version http://www.knowsky.com/3439.html follows this article. I tried it, about how to read the value of the new ID, it is still a difficult point. I would like to rationally