Search code examples
c#windows-8resourcesxnamonogame

How to open a file in the project as a stream?


I have a collection of text files in my project containing level information that I want to load as streams and read in XNA. I am using MonoGame XNA and targeting Windows RT. Let's say I want to open /Content/Levels/Level1.txt as a stream. How would I do this?

On some other platforms using C# I would set the file's build action to resource and use

Application.GetResourceStream

but this is not available in XNA.


Solution

  • There are two kinds of storage in an XNA game: Title Storage and User Storage. See What is Storage? To read data from Title Storage, use TitleContainer.OpenStream as in this example.