private void Button_Click(object sender, RoutedEventArgs e) { try { // arrays to store notes int N_files = Entries[0].Length; int N_folders = Entries[1].Length; string[] file_Notes = new string[N_files]; string[] folder_Notes = new string[N_folders]; // loop through entries and collect notes for (int i = 0; i < N_files; i++) { file_Notes[i] = ((fileStack.Children[i] as Expander).Content as TextBox).Text; } for (int i = 0; i < N_folders; i++) { folder_Notes[i] = ((folderStack.Children[i] as Expander).Content as TextBox).Text; } // save notes SavedDataClass Data_to_save = new SavedDataClass(); Data_to_save.fileEntries = Entries[0]; Data_to_save.fileNotes = file_Notes; Data_to_save.folderEntries = Entries[1]; Data_to_save.folderNotes = folder_Notes; SaveAsBinaryFormat(Data_to_save, "folderNotes.dat"); MessageBox.Show("Notes saved successfully!"); } catch { MessageBox.Show("Error while saving notes!"); } }
private SavedDataClass LoadFromBinaryFile(string fileName) { BinaryFormatter binFormat = new BinaryFormatter(); SavedDataClass savedData = new SavedDataClass(); using (Stream fStream = File.OpenRead(fileName)) { savedData = (SavedDataClass)binFormat.Deserialize(fStream); } return(savedData); }
private void onWindowLoad() { Entries = getFolderSturcture(); int N_files = Entries[0].Length; int N_folders = Entries[1].Length; string[] file_Notes = new string[N_files]; string[] folder_Notes = new string[N_folders]; // check if notes file exists if (File.Exists("FolderNotes.dat")) { // load saved data SavedDataClass savedData = new SavedDataClass(); savedData = LoadFromBinaryFile("folderNotes.dat"); // get notes for files for (int i = 0; i < N_files; i++) { int fileIndex = Array.IndexOf(savedData.fileEntries, Entries[0][i]); if (fileIndex > -1) { file_Notes[i] = savedData.fileNotes[fileIndex]; } } // get notes for folders for (int i = 0; i < N_folders; i++) { int folderIndex = Array.IndexOf(savedData.folderEntries, Entries[1][i]); if (folderIndex > -1) { folder_Notes[i] = savedData.folderNotes[folderIndex]; } } } string[][] Entries_Notes = { file_Notes, folder_Notes }; generateExpanders(Entries, Entries_Notes); }