I am very new to programming, so this may be a basic question. I am working in C#.net. I have a binary file consisting of multiple records, each one formatted like so:
Last name, First name Total points Percent
I need to populate a listbox by reading this file and returning an arraylist with the data, but when I try it comes up oddly formatted, with numbers that don't exist in the file (there are no total points over 400, no percent over 100). I need each line in the file to be displayed on its own line in the listbox, as I need to be able to select one line to add to an existing database table with the same fields (last name, first name, total, percent).
Also, the binary file was originally created with last name and first name separated by just a comma. In this program they are two separate fields and I'm not sure how to do that. If I just do the ReadString it reads it all as one.
Here is the code I have:
public ArrayList ReadBin(String filename)
ArrayList cgList = new ArrayList();
BinaryReader binfile = null;
binfile = new BinaryReader(
new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read));
while (binfile.PeekChar() != -1)
cg1 = new CourseGradesData();
cg1.Lname = binfile.ReadString();
cg1.Fname = binfile.ReadString();
cg1.Total = (binfile.ReadInt32());
cg1.Percent = binfile.ReadDecimal();
catch (System.IO.IOException exc)
Console.WriteLine(" Error in processing file"
I have attached the binary file I'm trying to read. Any help would be much appreciated.