3 Replies - 838 Views - Last Post: 25 August 2012 - 03:54 PM Rate Topic: -----

#1 nesa24casa  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 25-August 12

C# BinaryWriter replace hex in file problem

Posted 25 August 2012 - 03:38 PM

Hello,
i have made app that opens file with OpenFileDialog and writes a value into file. But it deletes all hex values in file.

BinaryWriter bw = new BinaryWriter bw = new BinaryWriter(File.OpenWrite(ofd.FileName));
            Byte[] Bytes = { 0x46, 0x46, 0x44 };
            bw.BaseStream.Position = (0x0106E);
bw.Write(Bytes);
bw.Flush();
bw.Close


Everything is deleted from file and only 464644 are in their possition and that ends file.
What i am doing wrong and how to do this right?
Thanks in advance.

This post has been edited by tlhIn`toq: 25 August 2012 - 03:48 PM
Reason for edit:: [code] your code here [/code] tags added


Is This A Good Question/Topic? 0
  • +

Replies To: C# BinaryWriter replace hex in file problem

#2 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4928
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: C# BinaryWriter replace hex in file problem

Posted 25 August 2012 - 03:49 PM

You are WRITING a file instead of APPENDING to the file.


See where you set it to File.OpenWrite instead of Apend on line 1?
Was This Post Helpful? 1
  • +
  • -

#3 nesa24casa  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 14
  • Joined: 25-August 12

Re: C# BinaryWriter replace hex in file problem

Posted 25 August 2012 - 03:54 PM

just solved it

BinaryWriter bw = new BinaryWriter(File.Open(ofd.FileName, FileMode.Open, FileAccess.ReadWrite));

Realy stupid thing i have done.
Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4928
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: C# BinaryWriter replace hex in file problem

Posted 25 August 2012 - 03:54 PM

.

This post has been edited by tlhIn`toq: 25 August 2012 - 03:54 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1