Skip to content

Having real problems with BinaryWriter file access

Grimtaz

Asked Feb 27, 2006, 10:10 AM EST1 answer
Share
LinkedInX

Ok so I'm tearing my hair out.  I've been trying for the last 2hrs to get this thing to work like it's supposed to. I have a binary file which I need to create or overwrite multiple times because the data is changing frequently.

Here is the code I'm using:

BinaryWriter dataOut = new BinaryWriter(new FileStream(datfilename, FileMode.Create, FileAccess.Write));

dataOut.Write(data);
....
....
dataOut.Close();

It works first time. But when called a second time it gives the error "The process cannot access the file .... because it is being used by another process."

Thats rubbish! It's been closed!!

Can somone please help me out??

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    LOL, sorry. It wasn't the Filestream that was causing the issue. It was the process after which emailed it as an attachment. Doh!
    0