Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# test if number exists in array and if not put it in Pin
Wheels01230-Dec-09 8:58
Wheels01230-Dec-09 8:58 
GeneralRe: C# test if number exists in array and if not put it in Pin
Luc Pattyn30-Dec-09 9:12
sitebuilderLuc Pattyn30-Dec-09 9:12 
GeneralRe: C# test if number exists in array and if not put it in Pin
PIEBALDconsult30-Dec-09 10:56
mvePIEBALDconsult30-Dec-09 10:56 
AnswerRe: C# test if number exists in array and if not put it in Pin
Islorvat30-Dec-09 8:47
Islorvat30-Dec-09 8:47 
GeneralRe: C# test if number exists in array and if not put it in Pin
Wheels01230-Dec-09 8:59
Wheels01230-Dec-09 8:59 
GeneralRe: C# test if number exists in array and if not put it in Pin
Alex Manolescu30-Dec-09 9:46
Alex Manolescu30-Dec-09 9:46 
GeneralRe: C# test if number exists in array and if not put it in Pin
#realJSOP30-Dec-09 9:48
professional#realJSOP30-Dec-09 9:48 
GeneralRe: C# test if number exists in array and if not put it in Pin
Alex Manolescu30-Dec-09 9:54
Alex Manolescu30-Dec-09 9:54 
GeneralRe: C# test if number exists in array and if not put it in Pin
#realJSOP30-Dec-09 23:45
professional#realJSOP30-Dec-09 23:45 
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 
AnswerRe: C# test if number exists in array and if not put it in Pin
Jimmanuel30-Dec-09 10:02
Jimmanuel30-Dec-09 10:02 
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
professional#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 

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.