private void txtTask_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return) { if (String.IsNullOrWhiteSpace(txtTask.Text)) { return; } string tasks = "- " + txtTask.Text; UpdateFile.Update(tasks); txtTask.Text = ""; txtTlist.Text = ""; taskList.Text = File.ReadAllText(UpdateFile.Globals.path); txtTlist.Text = File.ReadAllText(UpdateFile.Globals.path); } }
private void createBtn_Click(object sender, EventArgs e) { intClicks++; //int clicks = int.Parse(clicks); if (String.IsNullOrWhiteSpace(txtTask.Text)) { return; } string tasks = "- " + txtTask.Text; //string tasks = intClicks.ToString() + ". " + txtTask.Text; UpdateFile.Update(tasks); txtTask.Text = ""; taskList.Text = File.ReadAllText(UpdateFile.Globals.path); txtTlist.Text = File.ReadAllText(UpdateFile.Globals.path); //for (int index = 1; index < intClicks + 1; index++) //{ // string taskList = index + ". " + //} //TextReader rtxt = new StreamReader("C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\sample1\\text\\taskList.txt"); //rtxt.ReadToEnd(); //rtxt.Close(); //TextWriter txt = new StreamWriter("C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\sample1\\text\\taskList.txt"); //txt.Write(txtTask.Text); //txt.Close(); //this.Close(); // WORKS FOR ONE LINERS //string path = @"C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\sample1\\text\\taskList.txt"; //File.WriteAllText(path, txtTask.Text); //MessageBox.Show("wrote it to file"); //var str = File.ReadAllText(path); //txtTlist.Text = str; //else //{ // TextReader rtxt = new StreamReader("C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\sample1\\text\\taskList.txt"); // rtxt.ReadToEnd(); // rtxt.Close(); // TextWriter txt = new StreamWriter("C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\sample1\\text\\taskList.txt"); // txt.Write(txtTask.Text); // txt.Close(); // try // { // // Open the text file using a stream reader. // using (var sr = new StreamReader("C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\sample1\\text\\taskList.txt")) // { // // Read the stream as a string, and write the string to the console. // Console.WriteLine(sr.ReadToEnd()); // } // TextWriter wtxt = new StreamWriter("C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\sample1\\text\\taskList.txt"); // wtxt.Write(txtTask.Text); // wtxt.Close(); // } // catch (IOException ex) // { // Console.WriteLine("The file could not be read:"); // Console.WriteLine(ex.Message); // } // //TextWriter rtxt = new StreamWriter("C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\sample1\\text\\taskList.txt"); // //rtxt.Write(txtTlist.Text); // //rtxt.Close(); //} //var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "taskList.txt"); //var sb = new StringBuilder(); //for(int index = 1; index < intClicks+1; index++) //{ // sb.AppendLine(index.ToString() + ". "); //} //File.WriteAllText(fileName, sb.ToString()); //THIS IS THE CODE IF YOU TYPE OUT A PARAGRAPH TO WRITE TO TEXTFILE //TextWriter taskList = new StreamWriter("C:\\Users\\Angel\\Documents\\Spring 2021\\CSC 3380 - OOD\\Code\\TaskList.txt"); //taskList.Write(textBox1.Text); //taskList.Close(); // ROSS CODE //if (String.IsNullOrWhiteSpace(TaskList.Text)) //{ // return; //} //string tasks = TaskList.Text; //Console.WriteLine(tasks); //TaskList.Text = ""; //this.Close(); }