That is not quite sensible: a Hex file does not have lines.
Ar eyou trying to raed 50 bytes from one hex file, add it to another and then work out a checksum?
If so, then look at Stream.ReadBytes:
FileStream fs = File.OpenRead(filename);
int length = Math.Min(fs.Length, 50);
byte[] data = new byte[length];
fs.Read (data, 0, length);
and File.ReadAllBytes:
byte[] otherData = File.ReadAllBytes(path);
Then just assemble what you want into a separate array:
byte[] outData = new byte[4000 + length];
Array.Copy(otherData, outdata, 4000);
Array.Copy(data,0, outData, 4000, length)
Do your checksum - can't help you there without knowing what kind of checksum you are using...
"yes both files are INTEL hex record compatible, so when we add 50 lines at particular position then it moves other line so it changes address of each line
Please help"
In that case, you will have to read each line, process it into binary and store it.
You then insert your records with the appropriate address changes, and regenerate the file. Because each line contains an address, either you will have to replace hex values at address 4000 and on up, or insert. Either way, you need to generate the checksum: (trivial, the instructions are on the wiki page
http://en.wikipedia.org/wiki/Intel_HEX[
^] refered above)
You will have to use File.ReadAllLines to read each file, then convert each to binary (probably checking the checksums, it can't hurt and proves your checksum routine works)
Then merge, altering addresses as needed, and write the new file back out.
If this is a problem, then explain where and I'll try to help (without actually writing the whole app for you :laugh:)
Things to watch for: I don't know why you are doing this, but if the Hex file contains processor instructions then moving the data around may not work: For example, JUMP instructions can be coded to a specific address. If you move the data at that address, it will not move alter the JUMP instruction - it will go to the original address and execute the wrong instructions.