How to avoid my program from creating a new xml file everytime it starts up

Hello, i want to add a object to a xml file which is working fine while the program runs but whenever you compile it again. it will ovveride the previous file? i was think a if statement with file exists but i'm not sure

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(); } 

by barcemo via /r/csharp

Leave a Reply