Record Processing
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)
{
Using (Streamwriter SW = File. createtext ())
{
Sw. writeline (Info );
}
}
Else
{
Using (Streamwriter SW = File. appendtext ())
{
Sw. writeline (Info );
}
}
}
Catch (Filenotfoundexception filece)
{
Throw Filece;
}
Catch (Exception CE)
{
Throw CE;
}
}
}
Page call code
Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
// Checks whether the current user has accessed the website and records only the users that have not accessed the website.
If (Request. Cookies [ " Isexitsip " ] = Null )
{
// 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 tag to the user being accessed
Httpcookie Cokie = New Httpcookie ( " Isexitsip " );
Cokie. Values. Add ( " IP " , Request. userhostname );
Response. appendcookie (Cokie );
}
}
}
}