Record Processing
CopyCode The Code is as follows: using system;
Using system. IO;
/// <Summary>
/// File
/// </Summary>
Public class file
{
Protected string filepath;
/// <Summary>
/// File structure
/// </Summary>
/// <Param name = "filepath"> text path to be operated </param>
Public file (string filepath)
{
This. filepath = filepath;
}
/// <Summary>
/// Write text content
/// </Summary>
/// <Param name = "info"> write content </param>
Public void filewrite (string info)
{
Try
{
Fileinfo file = new fileinfo (filepath );
If (! File. exists)
{< br> using (streamwriter Sw = file. createtext ()
{< br> SW. writeline (Info);
}< BR >}< br> else
{< br> using (streamwriter Sw = file. appendtext ()
{< br> SW. writeline (Info);
}< BR >}< br> catch (filenotfoundexception filece)
{< br> throw filece;
}< br> catch (exception CE)
{< br> throw CE;
}< BR >}
page Call Code copy Code the code is as follows: public partial class _ default: system. web. UI. page
{< br> protected void page_load (Object sender, eventargs e)
{< br> If (! Ispostback)
{< br> // checks whether the current user has accessed the service. Only the unaccessed users are recorded.
If (request. cookies ["isexitsip"] = NULL)
{< br> // upload a TXT file every day
string filename = string. format ("{0} {1} {2}", datetime. now. year. tostring (), datetime. now. month. tostring (), datetime. now. day. tostring ();
file = new file (server. mappath ("~ /Test/"+ filename + ". TXT ");
file. filewrite (request. userhostname);
// Add an access flag to the user being accessed
httpcookie Cokie = new httpcookie ("isexitsip");
Cokie. values. add ("ip", request. userhostname);
response. appendcookie (Cokie);
}< BR >}