Click here to Skip to main content
15,887,477 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# test if number exists in array and if not put it in Pin
petercrab30-Dec-09 18:20
petercrab30-Dec-09 18:20 
GeneralRe: C# test if number exists in array and if not put it in Pin
Luc Pattyn31-Dec-09 0:24
sitebuilderLuc Pattyn31-Dec-09 0:24 
GeneralRe: C# test if number exists in array and if not put it in Pin
Alex Manolescu31-Dec-09 0:30
Alex Manolescu31-Dec-09 0:30 
GeneralRe: C# test if number exists in array and if not put it in Pin
Wheels01231-Dec-09 1:53
Wheels01231-Dec-09 1:53 
QuestionHow can I print-out my data in DataGridView using a printer? Pin
Emmet_Brown30-Dec-09 7:46
Emmet_Brown30-Dec-09 7:46 
AnswerRe: How can I print-out my data in DataGridView using a printer? Pin
sanforjackass30-Dec-09 8:13
sanforjackass30-Dec-09 8:13 
GeneralRe: How can I print-out my data in DataGridView using a printer? Pin
Emmet_Brown30-Dec-09 8:14
Emmet_Brown30-Dec-09 8:14 
QuestionI want to modify/replace some data from a binary file without loadig the file in memory. Pin
Alex Manolescu30-Dec-09 6:07
Alex Manolescu30-Dec-09 6:07 
My quest is simple and I have some ideas, but I wonder if you have a better idea Smile | :)

I have a binary file with some data in it, and I want to modify/replace data from position "x".
I've seen that if I want to modify/replace some data (bytes) from a binary file, I need to replace with the same bytes size.

Now I need a solution to do this.
I taught at a simple solution:
>read the binary file with a handler, and write to a new binary file with another handler
>when reading arrive at my "x" position, I write my own binary data.

My code is shown below:

public void MyWriteMethod()
        {
            int b;
            int x = 153; // the position I want to insert binary data

            Stream str = File.Open("dT.man", FileMode.Open);
            Stream strIndex = File.Open("dT.index", FileMode.CreateNew);
            
            BinaryReader br = new BinaryReader(str);            
            BinaryWriter bw = new BinaryWriter(strIndex);
            
            while ((b = br.BaseStream.ReadByte()) != -1)
            {
                if (br.BaseStream.Position == x)
                {
                    // below is the data that I want to write
                    bw.Write(1);
                    bw.Write("StringData");
                    bw.Write("StringData");
                    bw.Flush();
                    continue;
                }
                bw.Write(b);
            }

            bw.Flush();
            bw.Close();
            br.Close();

            str.Close();
            strIndex.Close();           
        }


Hope there is a better solution, something like seek into the binary file and replace the data. Big Grin | :-D

Cheer's,
Alex Manolescu.
AnswerRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
ProtoBytes30-Dec-09 6:39
ProtoBytes30-Dec-09 6:39 
GeneralRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
Alex Manolescu30-Dec-09 6:56
Alex Manolescu30-Dec-09 6:56 
GeneralRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
ProtoBytes30-Dec-09 7:07
ProtoBytes30-Dec-09 7:07 
GeneralRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
Alex Manolescu30-Dec-09 8:27
Alex Manolescu30-Dec-09 8:27 
GeneralRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
#realJSOP30-Dec-09 7:08
mve#realJSOP30-Dec-09 7:08 
GeneralRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
Alex Manolescu30-Dec-09 8:29
Alex Manolescu30-Dec-09 8:29 
AnswerRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
Luc Pattyn30-Dec-09 6:49
sitebuilderLuc Pattyn30-Dec-09 6:49 
GeneralRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
Alex Manolescu30-Dec-09 7:00
Alex Manolescu30-Dec-09 7:00 
GeneralRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
Luc Pattyn30-Dec-09 7:30
sitebuilderLuc Pattyn30-Dec-09 7:30 
GeneralRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
Alex Manolescu30-Dec-09 8:25
Alex Manolescu30-Dec-09 8:25 
AnswerRe: I want to modify/replace some data from a binary file without loadig the file in memory. Pin
petercrab30-Dec-09 17:59
petercrab30-Dec-09 17:59 
QuestionAbstracts: can I do better than this? Pin
MollyTheCoder30-Dec-09 4:45
MollyTheCoder30-Dec-09 4:45 
AnswerRe: Abstracts: can I do better than this? Pin
Luc Pattyn30-Dec-09 4:56
sitebuilderLuc Pattyn30-Dec-09 4:56 
GeneralRe: Abstracts: can I do better than this? Pin
MollyTheCoder30-Dec-09 5:22
MollyTheCoder30-Dec-09 5:22 
AnswerRe: Abstracts: can I do better than this? Pin
#realJSOP30-Dec-09 5:14
mve#realJSOP30-Dec-09 5:14 
AnswerRe: Abstracts: can I do better than this? Pin
DaveyM6930-Dec-09 5:20
professionalDaveyM6930-Dec-09 5:20 
AnswerRe: Abstracts: can I do better than this? Pin
Paulo Zemek30-Dec-09 5:23
mvaPaulo Zemek30-Dec-09 5:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.