public void OpenFile(string excusePath) { using (Stream input = File.OpenRead(excusePath)) { BinaryFormatter bf = new BinaryFormatter(); Excuse temp = (Excuse)bf.Deserialize(input); this.Description = temp.Description; this.LastUsed = temp.LastUsed; this.Results = temp.Results; } }
private void Open_Click(object sender, EventArgs e) { if (CheckChanged()) { openFileDialog1.InitialDirectory = currentFolder; openFileDialog1.Filter = "Excuse Files|*.excuse"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { bool clearForm = false; try { currentExcuse = new Excuse(openFileDialog1.FileName); try { UpdateForm(false); } catch (ArgumentOutOfRangeException ) { clearForm = true; } } catch (SerializationException) { MessageBox.Show("The excuse file '" + openFileDialog1.FileName + "' is invalid"); clearForm = true; } finally { if (clearForm) { currentExcuse.Description = ""; currentExcuse.Results = ""; currentExcuse.LastUsed = DateTime.Now; } } } } }
private void Random_Click(object sender, EventArgs e) { currentExcuse = new Excuse(random, currentFolder); UpdateForm(false); }