2012-03-16 101 views
0

我正在写一个小游戏为Windows Phone 7的 这是一个基础词汇的比赛,我有一个文本词典这基本上是有大量的单词一个巨大的文本文件。存储资源为Windows Phone 7

如何在模拟器中使用此功能。我发现我们只能访问我们的应用使用IsolatedStorage创建的文件。我应该在每次应用程序加载时手动创建此文件(这不是一种可行的方法),或者我可以以某种方式将文本文件与应用程序捆绑在一起。在后一种情况下,我怎样才能访问这个文件。

只是要清楚我不是在寻找隔离存储教程的链接。 我想将该文本文件添加到我的项目资源并将其复制到IsolatedStorage。我不知道如何做到这一点,如果有人可以帮助我,这将是伟大的。

回答

3

事实上,当你使用模拟器,你可以使用isolatedStorage,但如果你退出仿真器时,isolatedStorage被删除。

所以,你所要做的,是无法退出模拟器,让在IsolatedStorage文件,但你可以退出应用程序。


如何从内容写一个txt文件isolatedStorage

 IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 


     Stream yourFilepath = Application.GetResourceStream(new Uri("YourFilePath.txt", UriKind.Relative)).Stream; 
     StreamReader reader = new StreamReader(yourFilepath); 


     Stream yourIsolatedPath = new IsolatedStorageFileStream("YourFileIsolatedPath.txt", FileMode.CreateNew, myIsolatedStorage); 
     StreamWriter writer = new StreamWriter(yourIsolatedPath); 


     while (!reader.EndOfStream) 
     { 
      writer.WriteLine(reader.ReadLine()); 
     } 

此代码必须被放置在功能

private void Application_Launching(object sender, LaunchingEventArgs e) 
    { 

    } 

在App.xaml.cs

+0

这不是我在问什么。 从程序中创建文本文件是不可行的。我想在运行应用程序时将文件自动复制到IsolatedStorage中。 – nikhil 2012-03-16 14:34:38

+1

我刚才纠正答案:) – Mentezza 2012-03-16 14:58:18

+0

谢谢,这是我想要的。我会马上尝试。 – nikhil 2012-03-16 15:13:08