Saving to a xml file question

Hello, i'm saving my new artists into a xml file. I want to save multiple artist to that file but right now only one artist can be save

Here is my saving behaviour

public static void SaveData(object obj, string filename) { XmlSerializer sr = new XmlSerializer(obj.GetType()); TextWriter writer = new StreamWriter(filename); sr.Serialize(writer, obj); writer.Close(); }

this is the body of the save button

private void Save_Click(object sender, RoutedEventArgs e) { try {

 var artist = new Artist(); artist.ThisArtistName = ArtistName.Text; artist.thisArtistAddres = ArtistAddress.Text; List<Artist> ArtistList = new List<Artist>(); ArtistList.Add(artist); Savexml.SaveData(ArtistList, "ArtistList.xml"); } catch(Exception ex) { MessageBox.Show(ex.Message); } } 

and the variables within my class are the artist name and artist address

by barcemo via /r/csharp

Leave a Reply