开发者

FileStream.Write not Writing to File

I'm passing some Base64 e开发者_如何学Pythonncoded 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.


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.


You can try

var streamBytes = myMemoryStream.ToArray();
File.WriteAllBytes(myFilePath, streamBytes);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜