/// <summary> /// Save our equipment list using serialization /// </summary> /// <param name="toSave">Equipment list to save</param> /// <param name="filename">Filename to save the equipment list to</param> public static void saveEquipmentList(EquipmentList toSave, String filename) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, toSave); stream.Close(); }
// Stufffff /// <summary> /// Load our equipment list using serialization /// </summary> /// <param name="filename">Filename to load equipment list from</param> /// <returns>Object version of equipment list</returns> public static EquipmentList loadEquipmentList(String filename) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); EquipmentList result = (EquipmentList)formatter.Deserialize(stream); stream.Close(); return(result); }
private void btnLoad_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "List Files (*.lif)|*.lif|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { availableEquipment = Persistence.loadEquipmentList(openFileDialog.FileName); updateLists(); MessageBox.Show("Load Successful"); } catch (Exception ex) { MessageBox.Show("Sorry, couldn't load that file."); lblDebug.Text = ex.Message; } } }