I am trying to make an SMS Compose Task from which I can send group messages. The user adds phone numbers to an isolated storage file and I intend to take the numbers from there.
How do I take the phone numbers from there?
Also how to delete numbers from the isolated storage file?
Here is my isolated storage file code:
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
string fileName = "SOS Contacts.txt";
using (var isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
// we need to check to see if the file exists
if (!isoStorage.FileExists(fileName))
{
// file doesn't exist...time to create it.
isoStorage.CreateFile(fileName);
}
// since we are appending to the file, we must use FileMode.Append
using (var isoStream = new IsolatedStorageFileStream(fileName, FileMode.Append, isoStorage))
{
// opens the file and writes to it.
using (var fileStream = new StreamWriter(isoStream)
{
fileStream.WriteLine(PhoneTextBox.Text);
}
}
// you cannot read from a stream that you opened in FileMode.Append. Therefore, we need
// to close the IsolatedStorageFileStream then open it again in a different FileMode. Since we
// we are simply reading the file, we use FileMode.Open
using (var isoStream = new IsolatedStorageFileStream(fileName, FileMode.Open, isoStorage))
{
// opens the file and reads it.
using (var fileStream = new StreamReader(isoStream))
{
ResultTextBox.Text = fileStream.ReadToEnd();
}
}
}
}
Did you try using the
Application Settings
usingIsolated Storage
to store and retrieve data. As you're saving into theSettings
, you'll be able to retrieve it anywhere from your application.Perfect sample would be this.
The following sample is from msdn:
http://code.msdn.microsoft.com/windowsapps/Using-Isolated-Storage-fd7a4233
Hope it helps!