XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Reading from a .txt file? (Xbox 360 build)

Last post 05-03-2008 4:53 PM by christianv. 4 replies.
  • 05-01-2008 8:37 PM

    Reading from a .txt file? (Xbox 360 build)

    I was a part of a team that built an XNA game for the PC and I am currently trying to port the game to the Xbox. I have already run into a number of problems that I have fixed but I just came upon a new one. Our PC version of the game reads text from a .txt file to display on the screen when the player interacts with objects and NPCs. When I build the game for the Xbox version I get the following exception:

    A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
    An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    Additional information: Could not find file 'T:\584E07D1\Script.txt'.

    The file is there and it works fine on the PC. Does the Xbox 360 not allow reading from a .txt file? I am new at XNA and game development in general (this was a school project by the way), so any help would be greatly appreciated.
  • 05-01-2008 8:58 PM In reply to

    Re: Reading from a .txt file? (Xbox 360 build)

    The file may there on your PC, but it's not on your XBOX.

    You should add the txt file to your project, and set its properties so it is copied to the output directory.  Then it should be automatically placed alongside your binary when it is deployed to your xbox.  Then use a relative path to open it.

  • 05-01-2008 9:00 PM In reply to

    Re: Reading from a .txt file? (Xbox 360 build)

    Is that file location hard-coded?  I seem to remember reading that the 360's file system isn't the same as Windows.
  • 05-01-2008 9:07 PM In reply to

    Re: Reading from a .txt file? (Xbox 360 build)

    Read this thread: http://forums.xna.com/thread/58638.aspx. Should help you understand how to access files on the Xbox 360.

    NickGravelyn -- Microsoft XNA MVP
    Blog | XNA wiki | My Projects
    Write an Article, Win a Zune!
  • 05-03-2008 4:53 PM In reply to

    Re: Reading from a .txt file? (Xbox 360 build)

    A few Suggetions

    Get Storage device on the PC then open the container then you can see the actual titlepath,remember on PC your title path might be something like

    C:\Documents and Settings\username\My Documents\SavedGames\game\AllPlayers
    this is not the same as on XBOX:

    Code sample that might help you, use debug and concole,write to see values.

    iAsyncResult =
    Guide.BeginShowStorageDeviceSelector(null, null);
    storage_Device =
    Guide.EndShowStorageDeviceSelector(iAsyncResult)

    StorageContainer m_StoreageContainer= m_StorageDevice.OpenContainer("GameName");
    string m_TitleLocation = m_StoreageContainer.Path;

    Now you can do a few things like scan the folders and files

    DirectoryInfo dr = new DirectoryInfo(m_TitleLocation);
    if (dr.Exists)
    {
    foreach (DirectoryInfo dir in dr.GetDirectories())
    {
    foreach(FileInfo fl in dir.GetFiles("*.txt"))
    {}
    }
    }return null;
    }

    Note this code is for XNA2.0 not 1.

    Hope this helps ...

    www.cdktech.com - http://www.lab13.co.za/
Page 1 of 1 (5 items) Previous Next