Export (0) Print
Expand All

Storage Overview

The XNA Framework provides a set of classes in the Microsoft.Xna.Framework.Storage namespace that are used to read and write files from user storage and title storage, including player saves or title data.

Storage Devices

When programming with the XNA Framework, you read files from two general locations: 1) title storage, where the game executable and support files (shaders, meshes, textures, and so on) are located, and 2) user storage, the space a player provides for game data (such as saves) that is either locked to a particular profile or available to all players.

To access title storage, the XNA Framework provides the StorageContainer class, whose TitleLocation property contains a path to the location of the title itself. Title support files can be loaded based on this location.

To access user storage, the XNA Framework provides the StorageDevice class, which contains the BeginShowStorageDeviceGuide method. This method brings up a dialog box on Xbox 360 where the user selects a storage device (memory unit or hard drive). This method works asynchronously, notifying the caller with an IAsyncResult or a callback method when the user has chosen a device. For more information, see How to: Get a StorageDevice Asynchronously.

The StorageContainer instance provided by OpenContainer provides access to the selected device. Use System.IO objects, such as the File object, to open, copy, rename, or delete files, using StorageContainer.Path to determine the location of the files on the device.

Changes to the files within a StorageContainer on Xbox 360 do not take effect until the StorageContainer is disposed. For this reason, only one StorageContainer can be open on the same device for the same profile. Before opening a StorageContainer on a device, make sure that all previous StorageContainer objects opened for that profile have been disposed. To dispose a StorageContainer, call Dispose.

Storage Locations

Currently, the title location on a PC is the folder where the executable resides when it is run. Use the TitleLocation property to access the path.

User storage is in the My Documents folder of the user who is currently logged in, in the SavedGames folder. A subfolder is created for each game according to the titleName passed to the OpenContainer method. When no PlayerIndex is specified, content is saved in the AllPlayers folder. When a PlayerIndex is specified, the content is saved in the Player1, Player2, Player3, or Player4 folder, depending on which PlayerIndex was passed to ShowStorageDeviceGuide or BeginShowStorageDeviceGuide.

© 2015 Microsoft