Reputation: 107
I'm making an attendance app for teachers as a school project and I'm having problems with updating the xml file in isolated storage. I'm parsing the names of the students to a listbox from a custom xml file using LINQ to XML. Each listbox item has a checkbox and the name of the student. I then store the selected students to IsolatedStorage along with the current date using XmlSerializer. When I retrieve the stored xml file everything seems to be working but when I want to add more students, it just overwrites the previously stored file and doesn't add to it. How can I fix this bug so that it adds to the existing xml file instead of overwriting it?
Here are my save and load classes:
I appreciate all the help you can give me. Thanks!
Upvotes: 0
Views: 585
Reputation: 29963
Not on my dev machine to give you an example, but assuming your serialised file is a list of students, try the following methodology.
1) Deserialise the file you already have back into a list of objects.
2) Add the students to the deserialised list.
eg MyList.Add(new Student { Name = "Charlie Smith" });
or MyList.AddRange(MyListOfNewStudentsToAdd)
3) Serialise the whole list (with newly added data) back to the file.
That should work.
Upvotes: 1