I am having problems reading a file from the SDCard on my Cobra II board. The SDCard is a standard SanDisk 1.0 GB card formatted with FAT32 4096. I have tried FAT 16 also.
The exception I’m getting is System.IO.IOException - CLR_E_FILE_IO (1). It occurs from a FileStream.Read and from a ReadByte. I’m using the PersistentStorage class.
It doesn’t seem to matter whether I create the file on the PC or from my GHI code. If I create the file in code (Create, Write), I can read it just fine. But if I unmount the SDCard, then mount it and try to read, it fails. I’m assuming that the Create/Write does not physically write the file to the SDCard whereas the unmount does.
Within the FileInfo collection the file is there with all the correct properties (CanRead, Length, etc.).
Here is the code. It’s pretty much right from the example:
private void ReadFile(String FileName)
{
String RootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
FileStream FlashFile = new FileStream(RootDirectory + @ "\" + FileName, FileMode.Open, FileAccess.Read);
Byte[] Data = new Byte[FlashFile.Length];
FlashFile.Read(Data, 0, Data.Length);
}