public void ExportXml(DeckStructure deckStructure, String exportPath, String fileName) { XmlSerializer mySerializer = new XmlSerializer(typeof(DeckStructure)); TextWriter myTextWriter = new StreamWriter(exportPath + @"\" + fileName); mySerializer.Serialize(myTextWriter, myDeckStructure); myTextWriter.Close(); }
private void button_DeckWählen_Click(object sender, EventArgs e) { DeckAssistant myDeckAssistant = new DeckAssistant(); openFileDialog1.ShowDialog(); myDeckStructure = myDeckAssistant.DeserializeDeck(openFileDialog1.FileName); label_GewähltesDeck.Text = myDeckStructure.deckName; label_GewähltesDeck.Visible = true; //todo Liste mit den Zuletzt ausgewählten Decks erstellen. }
public DeckStructure DeserializeDeck(string filename) { DeckStructure nDeckStructure = new DeckStructure(); try { XmlSerializer mySerializer = new XmlSerializer(typeof(DeckStructure)); FileStream myFileStream = new FileStream(filename, FileMode.Open); XmlReader myReader = XmlReader.Create(myFileStream); nDeckStructure = (DeckStructure)mySerializer.Deserialize(myReader); myFileStream.Close(); } catch (Exception e) { Console.WriteLine(e); MessageBox.Show("Fehler bei der Deserialisierung"); } return(nDeckStructure); }