I'm working on porting a game from PC to Xbox 360.

When I want to create a level I read a .txt file that I store in my content I read the whole file as a string using this method


Where I'm passing in the full path to that file.

Later on in my code I parse that string to create whatever level I need.

When I try to deploy my game onto the Xbox I usually get an error stating

'System.IO.File' does not contain a definition for 'ReadAllText'

I was wondering if there was a simple way to read the text in a .txt file when I deploy onto the Xbox 360

  • 2
    \$\begingroup\$ msdn.microsoft.com/en-us/library/bb199094.aspx \$\endgroup\$ Apr 15, 2013 at 15:36
  • \$\begingroup\$ It's tangential to your question, but putting your text into a simple XML wrapper would allow you to use the content pipeline. msdn.microsoft.com/en-us/library/ff604982.aspx Although there is no technical rule against storing content data in the title container, using binary content instead would improve loading time, conserve (a tiny bit of) space, and allow you to keep save games away from vital game content files. As a best practice, content goes with the game, title storage is for auxiliary storage (saves, user settings, etc.) \$\endgroup\$ Apr 16, 2013 at 5:14

1 Answer 1


You can't access the file system on the Xbox 360 in the same you can on Windows; you need you use one of the storage APIs to access files.

There's an article here which outlines the different ways to handle IO in XNA 4.0 which will work on both the Xbox 360 and Windows. From a quick read it looks like you want to use Title Container, for which I've included some example code below (taken from the MSDN)

/// <summary>
/// This method opens a file using System.IO classes and the
/// TitleLocation property.  It presumes that a file named
/// ship.dds has been deployed alongside the game.
/// </summary>
private static void DoOpenFile()
        System.IO.Stream stream = TitleContainer.OpenStream("ship.dds");
        System.IO.StreamReader sreader = new System.IO.StreamReader(stream);
        // use StreamReader.ReadLine or other methods to read the file data

        Console.WriteLine("File Size: " + stream.Length);
    catch (System.IO.FileNotFoundException)
        // this will be thrown by OpenStream if gamedata.txt
        // doesn't exist in the title storage location

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .