namespace SimpleLicense { class Program { static void Main(string[] args) { string fileName = @"C:\\Temp\\test.txt"; try { // Check if file already exists. If yes, delete it. if (File.Exists(fileName)) { File.Delete(fileName); } // Create a new file Directory.CreateDirectory(Path.GetDirectoryName(fileName)); using (StreamWriter sw = File.CreateText(fileName)) { sw.WriteLine("Thermo Licensing System file"); sw.WriteLine("------------------------------------"); sw.WriteLine("Installed Date: {0}", DateTime.Now.ToString()); DateTime newDate = DateTime.Now.AddDays(30); DateTime date = DateTime.Now; sw.WriteLine("License Expires After"+" "+newDate); int numberOfDays = newDate.Subtract(date).Days; sw.WriteLine("Number of Days Remaining: " + " " + numberOfDays.ToString()); sw.Close(); } // Write file contents on console. using (StreamReader sr = File.OpenText(fileName)) { string s = ""; while ((s = sr.ReadLine()) != null) { Console.WriteLine(s); } Console.ReadLine(); } } catch (Exception Ex) { Console.WriteLine(Ex.ToString()); } } } }
Contents of .txt File Thermo Licensing System file ------------------------------------ Installed Date: 20-05-2014 16:01:42 License Expires After 20-06-2014 16:01:42 Number Of Days Remaining
:
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)