如何在windows phone中写入现有的文本文件?

时间:2013-09-07 10:00:35

标签: c# windows-phone-7 filestream file-handling

如果这是在我的解决方案资源管理器中打开文本文件“word.text”的代码。

       Stream txtStream = Application.GetResourceStream(new   Uri("/sample;component/word.txt", UriKind.Relative)).Stream;

        using (StreamReader sr = new StreamReader(txtStream))
        {
            string jon;
            while (!sr.EndOfStream) 
            {
              jon = sr.ReadLine();
              mylistbox.ItemSource = jon;
            }
        }

如何在现有文本文件中编写和附加?

1 个答案:

答案 0 :(得分:0)

这是一个例子

    public static void WriteBackgroundSetting(string currentBackground)
    {
        const string fileName = "RecipeHub.txt";
        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if(myIsolatedStorage.FileExists(fileName))
                myIsolatedStorage.DeleteFile(fileName);
            var stream = myIsolatedStorage.CreateFile(fileName);
            using (StreamWriter isoStream = new StreamWriter(stream))
            {
                isoStream.WriteLine(currentBackground);
            }
        }

    }