I have one problem which I cannot resolve (at least I didn't found solution yet...) I wanted to add data into IsolatedStorageSettings in WP8. My goal is to check if there are settings already in there, but when I want to check I get an exception which I cannot resolve.
private IsolatedStorageSettings appSettings = new IsolatedStorageSettings();
private void Button_Click(object sender, RoutedEventArgs e)
{
//correct this part
if (String.IsNullOrEmpty((string)appSettings["ICE1"])||
String.IsNullOrEmpty((string)appSettings["ICE2"]) ||
String.IsNullOrEmpty((string)appSettings["ICE3"]) ||
String.IsNullOrEmpty((string)appSettings["address"]) ||
String.IsNullOrEmpty((string)appSettings["fullName"]))
{
appSettings.Add("fullName", fullName.Text);
appSettings.Save();
appSettings.Add("address", address.Text);
appSettings.Save();
if (Regex.IsMatch(prefix1.Text, "^+\\d{2,3}") && Regex.IsMatch(number1.Text, "d{6,10}"))
{
appSettings.Add("ICE1", prefix1.Text + number1.Text);
appSettings.Save();
}
else
{
MessageBox.Show("Invalid prefix number, please use +01 and for numbers only 0-9...");
}
if (Regex.IsMatch(prefix2.Text, "^+\\d{2,3}") && Regex.IsMatch(number2.Text, "d{6,10}"))
{
appSettings.Add("ICE2", prefix2.Text + number2.Text);
appSettings.Save();
}
else
{
MessageBox.Show("Invalid prefix number, please use +01 and for numbers only 0-9...");
}
if (Regex.IsMatch(prefix2.Text, "^+\\d{2,3}") && Regex.IsMatch(number2.Text, "d{6,10}"))
{
appSettings.Add("ICE3", prefix2.Text + number2.Text);
appSettings.Save();
}
else
{
MessageBox.Show("Invalid prefix number, please use +01 and for numbers only 0-9...");
}
MessageBox.Show("Your information is saved...!");
}
else
{
//
appSettings["fullName"] = fullName.Text;
appSettings.Save();
appSettings["address"] = address.Text;
appSettings.Save();
if (Regex.IsMatch(prefix1.Text, "^+\\d{2,3}") && Regex.IsMatch(number1.Text, "d{6,10}"))
{
appSettings["ICE1"]= prefix1.Text + number1.Text;
appSettings.Save();
}
else
{
MessageBox.Show("Invalid prefix number, please use +01 and for numbers only 0-9...");
}
if (Regex.IsMatch(prefix2.Text, "^+\\d{2,3}") && Regex.IsMatch(number2.Text, "d{6,10}"))
{
appSettings["ICE2"] = prefix2.Text + number2.Text;
appSettings.Save();
}
else
{
MessageBox.Show("Invalid prefix number, please use +01 and for numbers only 0-9...");
}
if (Regex.IsMatch(prefix2.Text, "^+\\d{2,3}") && Regex.IsMatch(number2.Text, "d{6,10}"))
{
appSettings["ICE3"] = prefix3.Text + number3.Text;
appSettings.Save();
}
else
{
MessageBox.Show("Invalid prefix number, please use +01 and for numbers only 0-9...");
}
MessageBox.Show("Your information is saved...!");
}
Can someone explain how IsolatedStorageWorks?
How can I correct this part because this is causing the problem:
if (String.IsNullOrEmpty((string)appSettings["ICE1"])||
String.IsNullOrEmpty((string)appSettings["ICE2"]) ||
String.IsNullOrEmpty((string)appSettings["ICE3"]) ||
String.IsNullOrEmpty((string)appSettings["address"]) ||
String.IsNullOrEmpty((string)appSettings["fullName"]))
Do I need to do appSettings.Save() every each time when I wish to add the data or update-it...?
I also have another problem of getting data from IsolatedStorageSettings:
public WindowsPhoneControl2()
{
InitializeComponent();
}
string ice1;
string ice2;
string ice3;
PhoneCallTask ptask = new PhoneCallTask();
private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
ptask.PhoneNumber = ice1;
ptask.DisplayName = "Contact person 1";
ptask.Show();
}
private void Image_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
ptask.PhoneNumber = ice2;
ptask.DisplayName = "Contact person 2";
ptask.Show();
}
private void Image_Tap_2(object sender, System.Windows.Input.GestureEventArgs e)
{
ptask.PhoneNumber = ice3;
ptask.DisplayName = "Contact person 3";
ptask.Show();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
appSettings.Contains("fullName");
fullName.Text = (string)appSettings["fullName"];
address.Text = (string)appSettings["address"];
phone1.Text = (string)appSettings["ICE1"];
phone2.Text = (string)appSettings["ICE1"];
phone3.Text = (string)appSettings["ICE1"];
ice1 = phone1.Text;
ice2 = phone2.Text;
ice3 = phone3.Text;
}
especially this part which is supposed to get data from dictionary:
fullName.Text = (string)appSettings["fullName"];
address.Text = (string)appSettings["address"];
phone1.Text = (string)appSettings["ICE1"];
phone2.Text = (string)appSettings["ICE1"];
phone3.Text = (string)appSettings["ICE1"];