Click here to Skip to main content
15,891,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to edit a particular data in a binary file at a particular position by uploading a binary file.How can i do this in c#.

What I have tried:

code
<
using (FileStream sr = File.OpenRead("someFile.dat"))
{
sr.Seek(100, SeekOrigin.Begin);
int read = sr.ReadByte();
//...
}

>
Posted
Updated 17-Mar-19 21:21pm
Comments
Mehdi Gholam 18-Mar-19 3:09am    
...and what is your problem?

1 solution

Instead of seeking a stream, just read the whole dtaa in:
C#
byte[] data File.ReadAllBytes(pathToFile);
You can then use the array index to access each byte individually, and use File.WriteAllBytes to save the changed data when you are finished.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900