private void LoadUserPreference() { string userPreferenceSerialize = string.Empty; if (String.IsNullOrEmpty(Properties.Settings.Default.FileExtension) == true) { Models.ValidExtensionData valid = new Models.ValidExtensionData(); userPreferenceSerialize = JsonConvert.SerializeObject(valid); Properties.Settings.Default.FileExtension = userPreferenceSerialize; Properties.Settings.Default.Save(); } else { userPreferenceSerialize = Properties.Settings.Default.FileExtension; } int indexStart = userPreferenceSerialize.IndexOf('['); int indexEnd = userPreferenceSerialize.LastIndexOf(']'); int countCharEndString = userPreferenceSerialize.Length - indexEnd; string clean = userPreferenceSerialize.Substring(indexStart, userPreferenceSerialize.Length - (indexStart + countCharEndString) + 1); List <Models.ExtensionData> deserializedName = JsonConvert.DeserializeObject <List <Models.ExtensionData> >(clean); foreach (Models.ExtensionData item in deserializedName) { UserPreferenceList.Add(item); } }
private void SavePreferenceExecute(object obj) { Models.ValidExtensionData validExtensionData = new Models.ValidExtensionData(UserPreferenceList); string userPreferenceSerialize = JsonConvert.SerializeObject(validExtensionData); Properties.Settings.Default.FileExtension = userPreferenceSerialize; Properties.Settings.Default.Save(); // Configure the message box to be displayed string messageBoxText = "User Preference Saved"; string caption = "File Extension"; MessageBoxButton button = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.Information; // Display message box MessageBox.Show(messageBoxText, caption, button, icon); }