Search code examples
c#windows-phone-7windows-phonexna-4.0

WP7 Application.getResourceStream retunring null every time


Im trying to load a .txt file into a 2D array which i can do from a temp in isolated storage but our level builder writes to .txt files and moving them to isolated storage for each one is out of the question.

It is a windows phone game.

The text files Build action is set to content.

The Copy to output is set to Do Not Copy.

The file is in the base content folder.

        var ResrouceStream = Application.GetResourceStream(new Uri("grid_map;component/Data.txt", UriKind.Relative));
        if (ResrouceStream != null)
        {
          //do reading here
        }

I have a breakpoint on the if statment after it and when i check the var, it is still null and later on it throughs a null error in using (StreamReader Reader = new StreamReader(ResrouceStream .Stream))

because ResrouceStream is null.

Ive tried most ways or reading a .txt file but this seams the best way


Solution

  • If you want to load the file with Application.GetResourceStream, you have to set its build action to Resource, not Content.