Static Method conversion example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.