/// <summary> /// Creates a new CSVWriter object which will write to a new file /// This is performed weekly every monday or if a file does not exist for the week /// </summary> /// <param name="file_name">name of csv file</param> public void CreateLog(string file_name, FileMode mode) { //create a new writer try { if (mode == FileMode.Create) { int i = 0; string fname = _log_path + "\\" + file_name + "-" + i.ToString() + ".csv"; while (File.Exists(fname)) // this loop guarantees that it will not overwrite the file, but instead append a number to the end and create a new file { i += 1; fname = _log_path + "\\" + file_name + "-" + i.ToString() + ".csv"; } _writer = new CSVWriter(fname, mode); //basic header stuff for the csv //the name of the log, the time it started _writer.addToCurrent("Log for: "); _writer.addToCurrent(file_name); _writer.addToCurrent(" "); _writer.addToCurrent("Log Start Time: "); _writer.addToCurrent(DateTime.Now.ToShortTimeString()); _writer.WriteLine(); //and then header for the collumns _writer.addToCurrent("Time"); _writer.addToCurrent("ID Number"); _writer.addToCurrent("Problem"); _writer.addToCurrent("Description"); _writer.WriteLine(); } else if (mode == FileMode.Append) { _writer = new CSVWriter(file_name, mode); } } catch (Exception e) { MessageBox.Show(e.Message, "Error Creating Log"); return; } }