Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

How To: Load a Game Data File

Demonstrates how to use the File class to read a file from the game image directory.

The Complete Sample

The code in the topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.

Loading a Game Data File

To load a game data file

  1. Construct the full path to the file by combining StorageContainer.TitleLocation with the file name.

  2. Call File.Open with the full file path to get a FileStream containing the file data.

/// <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()
{
    FileStream file = OpenTitleFile(
        "ship.dds", FileMode.Open, FileAccess.Read);
    Console.WriteLine("File Size: " + file.Length);
    file.Close();
}
private static FileStream OpenTitleFile(
    string filename, FileMode mode, FileAccess access)
{
    string fullpath = Path.Combine(StorageContainer.TitleLocation, filename);
    return File.Open(fullpath, mode, access);
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.