Public voidSetupdatetime (stringstrnewdate) { Try { varPath =application.startuppath + configurationmanager.appsettings["Updatefile"]; //determines whether the file exists, does not exist, or the read value is displayed to the form if(!file.exists (path)) {FileStream FS1=NewFileStream (Path, FileMode.Create, FileAccess.Write);//Create write FileStreamWriter SW =NewStreamWriter (FS1); Sw. WriteLine (strnewdate);//Start Write ValueSW. Close (); FS1. Close (); } Else{FileStream fs=NewFileStream (Path, FileMode.Open, FileAccess.Write); StreamWriter SR=NewStreamWriter (FS); Sr. WriteLine (strnewdate);//Start Write ValueSr. Close (); Fs. Close (); } } Catch(Exception e) {logwrite.errorlog (e); } } PublicDateTime Getupdatedtime () {varReslut =DateTime.MaxValue; StreamReader SR=NULL; Try { varPath = System.Windows.Forms.Application.StartupPath + configurationmanager.appsettings["Updatefile"]; //determines whether the file exists, does not exist, or the read value is displayed to the formSR =NewStreamReader (path, encoding.default); String Line=Sr. ReadLine (); if(Line! =NULL) {Reslut=Convert.todatetime (line. ToString ()); } } Catch(Exception e) {logwrite.errorlog (e); } Sr. Close (); returnReslut; }
Read-write TXT file