Hi I am trying to read contents of a text file from a flash memory plugged into a usb host module this is the way I am doing It :
public void RemovableMedia_Insert(object sender, MediaEventArgs e)
{
deviceInserted = true;
led.TurnRed();
display.SimpleGraphics.Clear();
display.SimpleGraphics.DisplayText("Storage \"" + e.Volume.Name + "\" is inserted.", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 2, 10);
if (e.Volume.IsFormatted)
{
string[] files = Directory.GetFiles(e.Volume.RootDirectory);
int j = 0;
for (int i = 0; i < files.Length; i++)
{
string tmp = "";
try
{
tmp = files[i].ToString().Substring(files[i].Length - 15, 15);
}
catch { }
if (tmp == "PaymentList.txt")
{
j += 1;
display.SimpleGraphics.DisplayText(files[i].ToString().Substring(files[i].Length - 15, 15) + " was found", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 2, (uint)((i * 20) + 30));
display.SimpleGraphics.DisplayText("Click the send button to send the file", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 2, (uint)((i * 20) + 50));
FileStream fileStream = new FileStream(files[i], FileMode.Open);
data = new byte[fileStream.Length];
int k = fileStream.Read(data, 0, data.Length);
fileStream.Close();
try
{
FileContentText = new string(Encoding.UTF8.GetChars(data, 0, data.Length));
//FileContentText = new string(GetChars(data, 0, data.Length));
}
catch (Exception ex)
{
string s = ex.Message;
if (ex.InnerException != null)
s = s + ex.InnerException.Message;
if (ex.InnerException != null)
s = s + ex.StackTrace;
}
}
}
if (j == 0)
{
display.SimpleGraphics.DisplayText("There is no text file on your flash memory", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 2, 30);
display.SimpleGraphics.DisplayText("with the name : PaymentList", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Red, 2, 50);
fileWasFound = false;
}
else
{
fileWasFound = true;
}
}
else
{
Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
}
}
at the following line :
I get the following exception :
An unhandled exception of type 'System.Exception' occurred in mscorlib.dll
any helps would be appreciated .