How to write to existing text file in Windows phone?

If this is the code when I open the text file "word.txt" in my solution explorer.

       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;
            }
        }

      

How to write and append to an existing text file?

0


source to share


1 answer


Here's an example



    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);
            }
        }

    }

      

0


source







All Articles