I am trying to do a setting page where the user can choose the number of question, song and passing rate from listpicker control..
Then the selected index of the question, song and passing rate will be write into isolated storage.
Below is my code:
int indexQues;
string rate;
private void saveBtn_Click(object sender, RoutedEventArgs e)
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists("SettingFolder\\queSetting.txt"))
{
myIsolatedStorage.DeleteFile("SettingFolder\\queSetting.txt");
}
if (myIsolatedStorage.FileExists("SettingFolder\\rateSetting.txt"))
{
myIsolatedStorage.DeleteFile("SettingFolder\\rateSetting.txt");
}
}
indexQues = queListPicker.SelectedIndex;
rate = rateListPicker.SelectedItem.ToString();
//Save the number of question to answer when the alarm ring
//Obtain the virtual store for application
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFile myStore1 = IsolatedStorageFile.GetUserStoreForApplication();
//Create a new folder and call it "AlarmFolder"
myStore.CreateDirectory("SettingFolder");
//Retrieve the content of "noOfQues"
//And write it into queSetting.txt
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("SettingFolder\\queSetting.txt", FileMode.Append, myStore));
StreamWriter writeFile1 = new StreamWriter(new IsolatedStorageFileStream("SettingFolder\\rateSetting.txt", FileMode.Append, myStore));
writeFile.Write(indexQues);
writeFile1.Write(rate);
writeFile.Close();
writeFile1.Close();
MessageBox.Show("Setting Saved");
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
The above code allow me to write into the isolated storage but there is a error when i trying to save for the third time.
The error was "IsolatedStorageException was unhandled" An error occurred while accessing IsolatedStorage.