Search code examples
c#xamlwindows-phone-8

After writing, the file is not modified on Windows Phone 8.0


During the execution of this script it is not detected any error, but the file isn't modified. Reading works, writing strangely not.

My script for writing:

private void firstLaunch(){
    try { 
        StreamWriter outfile = new StreamWriter("Path/something.txt");
        outfile.WriteLine("somethingElse");
        outfile.Close();
    }
    catch (IOException ex){
        MessageBox.Show(ex.Message);
    }
}

The file already exists and has already been included in the project with visual studio. At the moment it is completely empty.

Could you help me?


Solution

  • You can use something like this:

    var res = App.GetResourceStream(new Uri("test.txt", UriKind.Relative));
    var txt = new StreamReader(res.Stream).ReadToEnd();
    

    Just make sure that the file has the Build Action set to Content. If the file is empty, I would recommend creating one in the folder of your app using IsolatedStorage. That way you can check with IsoStoreSpy the contents of your file.