I Save An onject into a xml file with serialize like this:
FileStream stream = new FileStream(tempFilename,FileMode.Create);
XmlSerializer serializer = new XmlSerializer(newType);
serializer.Serialize(stream,objectname);
but with this code i can just enter one item in my xml file and it will be overwrite if i insert new item in it.how can i enter multiple item in my file?Sholud I Use List For it?
I do this quite often. I usually use a top level class that encapsulates the collection property as a member and has a one to one relationship with the xml file. Members of that class can be collections or simple attributes etc.
Here is a code snippet for having a collection of custom objects:
And then if you want to encapsulate your collection inside another class which will be serialized, see the bottom property of this class:
And to finish off the code example, here is my top level class for this hierarchy: