从隔离的存储文件中添加多个联系人到短信撰写任务
本文关键字:联系人 写任务 隔离 存储文件 添加 | 更新日期: 2023-09-27 18:17:40
我正试图使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();
}
}
}
}
您是否尝试使用Application Settings
使用Isolated Storage
来存储和检索数据?当您保存到Settings
时,您将能够从应用程序的任何地方检索它。
完美的例子是这样的。
以下示例来自msdn: http://code.msdn.microsoft.com/windowsapps/Using-Isolated-Storage-fd7a4233希望有帮助!