public static TopicJsonData LoadFile(string filePath) { if (!File.Exists(filePath)) { return(null); } string json = File.ReadAllText(filePath); TopicJsonData retVal = null; try { retVal = JsonConvert.DeserializeObject <TopicJsonData>(json); return(retVal); } catch { return(null); } }
private void LoadTopics() { _flashcardFile = Common.DataFilePath; if (Persistence.FileExists(_flashcardFile)) { _data = Persistence.LoadFile(_flashcardFile); if (_data == null) { new MyMessageBox(Constants.TITLE_ATTENTION, string.Format(Constants.ERROR_LOADING_DATA, _flashcardFile), System.Windows.Forms.MessageBoxButtons.OK).ShowDialog(); } } else { _data = new TopicJsonData(); SaveTopics(); } }
public static void SaveFile(TopicJsonData data, string filePath) { string json = JsonConvert.SerializeObject(data, Formatting.Indented); File.WriteAllText(filePath, json); }