Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How To: Enumerate Files

This example demonstrates how to use the StorageContainer class to get a list of save game files in the title storage area on a device specified by the gamer. This example assumes you have already obtained a StorageDevice. To obtain a StorageDevice, see How To: Get a StorageDevice Asynchronously.

The Complete Sample

The code in this tutorial illustrates the technique described in the text. A complete code sample for this tutorial is available for you to download, including full source code and any additional supporting files required by the sample.

To enumerate save game files in title storage

  1. Call the Guide.BeginShowStorageDeviceSelector method to obtain a device index indicating which device the user prefers.
  2. Open a StorageContainer on the device, passing the name of your title.
  3. Call Directory.GetFiles. Directory.GetFiles returns a collection of strings, where each string is the name of a file in the container.
  4. Dispose the StorageContainer.
private static void DoEnumerate(StorageDevice device)
{
    // Open a storage container.
    StorageContainer container =
        device.OpenContainer("StorageDemo");

    ICollection<string> FileList = Directory.GetFiles(container.Path);
    foreach (string filename in FileList)
    {
        Console.WriteLine(filename);
    }

    // Dispose the container.
    container.Dispose();
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.