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

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

Last post 07-25-2008 8:40 AM by General Hank. 7 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.

    Nick Gravelyn -- Microsoft XNA MVP
    Blog | XNA Wiki | FX-izer | EasyZip | Current Adventures | Next-Gen
  • 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/
  • 07-24-2008 11:50 PM In reply to

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

    Hi all,

    Sorry to bring this post "back from the dead" but i'm having the same problem. I've followed the links from the replies given by other members and followed all the tutorials laid out by the MSDN website but i still can't get my .txt to load on my xbox 360. I've gone to the option for test.txt and selected "copy always" under "Copy to output". Any ideas where i could be going wrong?

     here is the code i'm using to get the path and then load the .txt file. I got the code from http://msdn.microsoft.com/en-us/library/bb199095.aspx.


            // If a save is pending, save as soon as the (i'm loading text.txt here instead) 
            // storage device is chosen 
            if ((GameSaveRequested) && (result.IsCompleted)) 
            { 
                StorageDevice device = Guide.EndShowStorageDeviceSelector(result); 
                if (device.IsConnected) 
                { 
                    // Open a storage container. 
                    StorageContainer container = 
                        device.OpenContainer("WindowsGame1"); 
     
                    // Add the container path to our file name. 
                    string filename = Path.Combine(container.Path, "test.txt"); 
     
                    FileStream file = File.Open(filename, FileMode.Open); 
                    file.Close(); 
     
                    // Dispose the container. 
                    container.Dispose(); 
                } 
     
                // Reset the request flag 
                GameSaveRequested = false
            } 
  • 07-25-2008 12:19 AM In reply to

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

    You don't need to mess with storage containers if you just want to read a data file that was deployed as part of your game. Storage containers are for if you want to create save games in new folders while the game is running.

    If the file was deployed from Visual Studio, use StorageContainer.TitleLocation to get the path where your game is running from.


    XNA Framework Developer - blog - homepage
  • 07-25-2008 8:40 AM In reply to

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


    Shawn Hargreaves:
    You don't need to mess with storage containers if you just want to read a data file that was deployed as part of your game. Storage containers are for if you want to create save games in new folders while the game is running.

    If the file was deployed from Visual Studio, use StorageContainer.TitleLocation to get the path where your game is running from.


     Thanks Shawn, It worked!

Page 1 of 1 (8 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG