using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; using System.Text; namespace UpdateConfigDamlDate { class Program { static void Main(string[] args) { try { string damlPath = ""; if (args.Count() > 0) { damlPath = args[0].ToString(); } if (damlPath.Length == 0) { damlPath = Properties.Settings.Default.damlDefaultPath.ToString(); } if (File.Exists(damlPath) == true) { if (File.Exists(damlPath + ".bak") == true) { File.Delete(damlPath + ".bak"); } File.Copy(damlPath,damlPath + ".bak"); string[] theRows = File.ReadAllLines(damlPath); //search for the row int dataRow = 0; for (int i = 0; i < theRows.Count(); i++) { if (theRows[i].Contains("") == true) { dataRow = i; break; } } if(dataRow!=0) { //determine spaces in front of int spaces = theRows[dataRow].IndexOf('<'); if (spaces == -1) { spaces = 0; } //update the date to NOW DateTime now = DateTime.Now; DateTime adjustedTime = now - TimeSpan.FromSeconds(now.Second); String newLine = "" + adjustedTime.ToString("MM/dd/yyyy hh:mm:ss tt") + ""; //add needed spaces to the result theRows[dataRow] = newLine.PadLeft(newLine.Length+spaces,' '); //write the file File.WriteAllLines(damlPath, theRows); } else { Console.WriteLine("File and path provided exists but tag not found."); throw new Exception("File and path provided exists but tag not found."); } } else { Console.WriteLine("File or path provided, " + damlPath + ", does not exist."); throw new Exception("File or path provided, " + damlPath + ", does not exist."); } Environment.Exit(0); } catch (Exception eX) { //critical error, most likely permissions Console.WriteLine("Error: " + eX.Message.ToString()); Environment.Exit(-1); } } } }