private void btnUptade_Click(object sender, EventArgs e) { ReminderFilePath = @"data/" + MainWindow.username + "Reminder.csv"; string type; if (rdobtnMeeting.Checked) { type = rdobtnMeeting.Text; } else { type = rdobtnTask.Text; } try { MeetingTaskReminder reminder = new MeetingTaskReminder(txtboxDate.Text, mtxtboxTime.Text, txtSummary.Text, txtDescription.Text, type, MainWindow.username); var file = new List <string>(System.IO.File.ReadAllLines(ReminderFilePath)); file.Insert(lstReminder.FocusedItem.Index, reminder.ReminderToCsv()); file.RemoveAt(lstReminder.FocusedItem.Index + 1); System.IO.File.WriteAllLines(ReminderFilePath, file.ToArray()); btnList_Click(sender, e); } catch (Exception) { MessageBox.Show("Select a reminder for updating."); } }
public static void SaveCsv(MeetingTaskReminder reminder, string csvPath) { try { using (StreamWriter writer = File.AppendText(csvPath)) { writer.WriteLine(reminder.ReminderToCsv()); } } catch (Exception) { Console.WriteLine("The file could not be write:"); } }