M
M
Michael2020-11-09 13:32:18
WPF
Michael, 2020-11-09 13:32:18

How to concatenate two serialized files?

There is a certain program in which I realized saving the data entered by the user to a file.

SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                Filter = "DF файлы (*.df)|*.df"
            };

            if (saveFileDialog.ShowDialog() == true)
            {
                Mouse.SetCursor(Cursors.Wait);

                using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create))
                {
                    /*var serializer = new XmlSerializer(typeof(ObservableCollection<ListBoxItemVM>));
                    serializer.Serialize(fs, DevList);*/
                    DataContractSerializer ser = new DataContractSerializer(typeof(ObservableCollection<ListBoxItemVM>));
                    ser.WriteObject(fs, DevList);
                }

                Mouse.SetCursor(Cursors.Arrow);
                MessageBox.Show(Application.Current.MainWindow, "Данные сохранены.", "Информация", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.Cancel);
            }

From the ListBoxItemVM, I removed some fields and threw them in a separate window. Now I need to save both files when saving. I think to do this, I save one file somewhere in a temporary folder, then the second file, then I write these files to an archive with the name that the user specified.
When opening, the process is reversed, unzipped the archive, received 2 files and deserialized each of them.
Due to my little programming experience in C #, I had a question as to whether this method is correct, maybe there is a better, more optimized way to do this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-11-09
@mscrack

Create 3 class with 2 fields and serialize it. And the fact that you came up with a bicycle and crutches. Well, or make a zip archive and shove both files there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question