title: Store Date to a .txt file only once using c#
body: <p>I have written code that stores the date to a .txt file as shown. I am able to store the current date and time. I want that the date should be set only once when the application is executed for the first time.</p>
  
  <p><b>Installed Date</b>: Set to the date when the application is executed the first time and should not change irrespective of how many time the application is executed</p>
  
  <p>I am trying to implement 30Days licensing. I want that when the application is executed for the very first time, the date when he executed the application should be stored into the .txt file and should not change, so that the remaining days could be calculated on the basis of that. My main aim is to stop the user from using my application after 30 days</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
  
          string fileName = @"C:\\Temp\\test.txt";
  
          try
          {
  
              // 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());
          }
      }
  }
  
  Output (.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
  </code></pre>