private async void btnSave_Click(object sender, RoutedEventArgs e) { Debug.WriteLine("Saving questions..."); QuestionList qList = new QuestionList(); String[] questions = new String[3]; questions[0] = txtQuestion1.Text; questions[1] = txtQuestion2.Text; questions[2] = txtQuestion3.Text; qList.Questions = new List <String>(questions); Debug.WriteLine("Questions: " + qList.ToJson()); Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile questionsFile = await storageFolder.CreateFileAsync(QUESTIONS_FILE, Windows.Storage.CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteTextAsync(questionsFile, qList.ToJson()); this.loadQuestionsFromStorage(); }
private async void loadQuestionsFromStorage() { try { Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile questionsFile = await storageFolder.GetFileAsync(QUESTIONS_FILE); String questionsJson = await Windows.Storage.FileIO.ReadTextAsync(questionsFile); QuestionList questionsList = DementiaApp.QuestionList.FromJson(questionsJson); Debug.WriteLine("Read stored questions: " + questionsList.ToJson()); txtQuestion1.Text = questionsList.Questions[0]; txtQuestion2.Text = questionsList.Questions[1]; txtQuestion3.Text = questionsList.Questions[2]; } catch { Debug.WriteLine("Exception trying to read file " + QUESTIONS_FILE); } }