Sunday, December 20, 2009

How to enumerate storage cards in .NETCF

In Windows Mobile, external storage cards are usually represented as the '\SD Card' or '\Storage Card' folder, this varies from device to device. A simple way to enumerate the external storage cards is to check all directories under the root directory that have the temporary attribute flag set.

Here's a quick way to do so in .NETCF:

public static List<string> GetStorageCards()
{
    var list = new List<string>();
    var root = new DirectoryInfo("\\");
    foreach (DirectoryInfo directory in root.GetDirectories()) 
    {
        if (FileAttributes.Temporary == (directory.Attributes & FileAttributes.Temporary))
            list.Add(directory.Name);
    }
    return list;
}

1 comment:

Anonymous said...

thanks, helpful article.