views:

340

answers:

1

I'm passing some Base64 encoded strings through WCF, and I'm attempting to write them to a file. However, despite the fact that my FileStream object has a Length greater than 0, my file on disk remains empty.

FileStream fs = new FileStream(Config.Instance.SharedSettings.SaveDir + StudyInstance.StudyId + "\\tmp.ext", FileMode.Create);

EncodeBlock eb = new EncodeBlock();

while (eb.Part != eb.OfParts || eb.OfParts == 0)
{
    eb.ToDecode = ps.StudyService.GetInstancePart(StudyInstance, s, eb.Part+ 1, Config.Instance.ClientSettings.AppData);
    eb = Base64Encoder.Decode(eb);
    fs.Write(eb.ToEncode, 0, eb.ToEncode.Length);
}

fs.Close();

eb.ToEncode's length is always greater than 0, fs.Length is always greater than 0, and yet my "tmp.ext" file is created, but remains empty. fs.CanWrite is always also true.

+5  A: 

Have you tried calling FileStream.Flush?

Call it just before you Close the stream.

You should also use a "using" statement to ensure the stream is cleaned up.

Simon
this would be my assumption
Alastair Pitts
It's my understanding that closing a FileStream automatically flushes the buffer. You're right about the `using` statement
md5sum