0

我正在尝试制作一个 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();
           }
       }
   }
}
4

1 回答 1

0

您是否尝试过使用Application SettingsusingIsolated Storage来存储和检索数据。当您保存到 中时Settings,您将能够从应用程序的任何位置检索它。

完美的样品就是这个

以下示例来自 msdn:

http://code.msdn.microsoft.com/windowsapps/Using-Isolated-Storage-fd7a4233

希望能帮助到你!

于 2014-08-13T07:35:52.713 回答