Binary .dat files
-
Hi Guys, Does anyone know how to deal with leagcy binary .dat files in .Net i have a few systems in C that write to .dat files 1 example is the following structure: typedef struct AccountIndexData { char Account[12]; long Record; } AccountIndex; typedef struct AccountDataFormat{ char Account[12]; char Company[32]; char Address[4][32]; char TelFax[2][18]; char Contact[22]; int PriceLevel; int Stop; int Cash; long First; long Last; long Limit; long Balance[5]; int Lock; } AccountData; My question is how do i handle these files in & retrieve information from a .Net application Thanks Keith
-
Hi Guys, Does anyone know how to deal with leagcy binary .dat files in .Net i have a few systems in C that write to .dat files 1 example is the following structure: typedef struct AccountIndexData { char Account[12]; long Record; } AccountIndex; typedef struct AccountDataFormat{ char Account[12]; char Company[32]; char Address[4][32]; char TelFax[2][18]; char Contact[22]; int PriceLevel; int Stop; int Cash; long First; long Last; long Limit; long Balance[5]; int Lock; } AccountData; My question is how do i handle these files in & retrieve information from a .Net application Thanks Keith
-
Hi Guys, Does anyone know how to deal with leagcy binary .dat files in .Net i have a few systems in C that write to .dat files 1 example is the following structure: typedef struct AccountIndexData { char Account[12]; long Record; } AccountIndex; typedef struct AccountDataFormat{ char Account[12]; char Company[32]; char Address[4][32]; char TelFax[2][18]; char Contact[22]; int PriceLevel; int Stop; int Cash; long First; long Last; long Limit; long Balance[5]; int Lock; } AccountData; My question is how do i handle these files in & retrieve information from a .Net application Thanks Keith
If the file is a flat file (like old C days), just create a class, similar to structure above. Then use a streamReader to read the info, and fill the object: Something like: while ((line = sr.ReadLine()) != null) { myClass.myProperty1 = line.Substring(0,5); myClass.myProperty2 = line.Substring(5,2); //etc..etc.. }
-
If the file is a flat file (like old C days), just create a class, similar to structure above. Then use a streamReader to read the info, and fill the object: Something like: while ((line = sr.ReadLine()) != null) { myClass.myProperty1 = line.Substring(0,5); myClass.myProperty2 = line.Substring(5,2); //etc..etc.. }
-
Hi Guys, Does anyone know how to deal with leagcy binary .dat files in .Net i have a few systems in C that write to .dat files 1 example is the following structure: typedef struct AccountIndexData { char Account[12]; long Record; } AccountIndex; typedef struct AccountDataFormat{ char Account[12]; char Company[32]; char Address[4][32]; char TelFax[2][18]; char Contact[22]; int PriceLevel; int Stop; int Cash; long First; long Last; long Limit; long Balance[5]; int Lock; } AccountData; My question is how do i handle these files in & retrieve information from a .Net application Thanks Keith
Use BinaryReader and its specialized methods such as ReadInt16 as appropriate. Do not assume you can read everything using strings, that will fail due to terminating nulls, and the difference between ASCII and Unicode. Also be careful when reading characters: if the file got created by a C/C++ program using char (8 bit each), you should read each char with ReadByte and convert to Char (which takes 16-bit). :)
Luc Pattyn
-
Use BinaryReader and its specialized methods such as ReadInt16 as appropriate. Do not assume you can read everything using strings, that will fail due to terminating nulls, and the difference between ASCII and Unicode. Also be careful when reading characters: if the file got created by a C/C++ program using char (8 bit each), you should read each char with ReadByte and convert to Char (which takes 16-bit). :)
Luc Pattyn