Here is a design to save the current state of the program:

Model model = new Model(); FileStream fs = File.Create("save.dat"); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, model); fs.Close(); 

How to make so that when saving happened not rewriting of the existing file, but new saving? On MSDN I found only an option with redefining the save location.

    2 answers 2

    KO reports: in order to save data to a new place, you must give the file a new name

    • The question was asked to find out how to give the file a name and make the next save. for example, the user clicks a button and a window appears where you are prompted to enter the file name and save directory. I have, so far, when I click it, it saves with overwriting. - cruim
    • @cruim well and ask a question about the request for the file name! And better - google, examples in the network - a cloud! Why are you asking about the File.Create method, as if the problem is in it? - Pavel Mayorov
    1. Create another file. This is the most logical option. I would use the date in the format yyyy_MM_dd HH_mm_ss as part of its name.

    2. Just open the file to add to the end. It is simple to write, but how then to read a certain piece - you have to think.

    3. Use alternate file streams. I don’t know about their support with .net, i.e. it is quite possible that winapi will have to be used. And in general, I do not recommend, because alternative streams can be lost when copying.