private void WriteBooks() { try { using (StreamWriter writeData = new StreamWriter("dataBooks.xml")) { XmlDictionarySerialization.Serialize(writeData, books); } } catch (IOException ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK); } }
public void ReadBooks() { if (!File.Exists("dataBooks.xml")) { return; } try { using (StreamReader read = new StreamReader("dataBooks.xml")) { XmlDictionarySerialization.Deserialize(read, books); } } catch (IOException ex) { MessageBox.Show(ex.ToString(), "Reading error", MessageBoxButtons.OK); } }