Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. IO;
Using system. text;
/// <Summary>
/// Summary of createhtml
/// </Summary>
Public class createhtml
{
Public createhtml ()
{
//
// Todo: add the constructor logic here
//
}
Public bool createhtm (string strtext, string strcontent, string strauthor)
{
String yearstring = datetime. Now. year. tostring ();
String monthstring = datetime. Now. Month. tostring ();
String daystring = datetime. Now. Day. tostring ();
String filename = yearstring + monthstring + daystring + datetime. Now. millisecond. tostring () + ". html ";
Directory. createdirectory (httpcontext. Current. server. mappath ("" + yearstring + "//" + monthstring + "//" + daystring + ""));
Encoding code = encoding. getencoding ("UTF-8 ");
String temp = httpcontext. Current. server. mappath ("htmlpage.htm ");
Streamreader sr = NULL;
Streamwriter Sw = NULL;
String STR = "";
// Read the Template
Try
{
Sr = new streamreader (temp, Code );
STR = Sr. readtoend ();
}
Catch (exception exp)
{
Httpcontext. Current. response. Write (exp. Message );
Httpcontext. Current. response. End ();
Sr. Close ();
}
// Replace
STR = Str. Replace ("showarticle", strtext );
STR = Str. Replace ("biaoti", strtext );
STR = Str. Replace ("content", strcontent );
STR = Str. Replace ("author", strauthor );
Try
{
Sw = new streamwriter (httpcontext. current. server. mappath ("" + yearstring + "//" + monthstring + "//" + daystring + "//" + filename + ""), false, Code );
Sw. Write (STR );
Sw. Flush ();
}
Catch (exception exp)
{
Httpcontext. Current. response. Write (exp. Message );
Httpcontext. Current. response. End ();
}
Finally
{
Sw. Close ();
}
Return true;
}
}
# C # column