Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Binary .dat files

Binary .dat files

Scheduled Pinned Locked Moved C#
tutorialquestioncsharp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KeithF
    wrote on last edited by
    #1

    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

    E E L 3 Replies Last reply
    0
    • K KeithF

      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

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      Try looking at the System.IO.BinaryReader class.

      1 Reply Last reply
      0
      • K KeithF

        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

        E Offline
        E Offline
        ednrgc
        wrote on last edited by
        #3

        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.. }

        K 1 Reply Last reply
        0
        • E ednrgc

          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.. }

          K Offline
          K Offline
          KeithF
          wrote on last edited by
          #4

          ednrgc wrote:

          If the file is a flat file (like old C days), just create a class, similar to structure above.

          Yes it is a flat file. Thanks for the help i'll give that a go Keith

          1 Reply Last reply
          0
          • K KeithF

            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

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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

            K 1 Reply Last reply
            0
            • L 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

              K Offline
              K Offline
              KeithF
              wrote on last edited by
              #6

              Thanks Luc Keith

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups