namespace Problem1_CalebFontenot { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void openButton_Click(object sender, EventArgs e) { // Create StreamReader StreamReader inputFile = null; // Read the contents of the text file. if (openFileDialog1.ShowDialog() == DialogResult.OK) { inputFile = File.OpenText(openFileDialog1.FileName); } // Clear the listbox. listBox1.Items.Clear(); while (!inputFile.EndOfStream) { listBox1.Items.Add(inputFile.ReadLine()); } } private void saveButton_Click(object sender, EventArgs e) { try { StreamWriter sw = null; //Open the save file dialog. if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string s = saveFileDialog1.FileName; sw = File.CreateText(s); for (int i = 0; i < listBox1.Items.Count; i++) { sw.WriteLine(listBox1.Items[i].ToString()); } sw.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }