我正在尝试制作一个 SMS 撰写任务,我可以从中发送群组消息。用户将电话号码添加到一个隔离的存储文件中,我打算从那里获取这些号码。
我如何从那里获取电话号码?
另外如何从隔离的存储文件中删除数字?
这是我的隔离存储文件代码:
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();
}
}
}
}