tags:

views:

903

answers:

3

Is there a max length that a stream writer can write out to a file? Or is there a max length that WriteLine() can output? I am trying to write some data to a file but all of the data does not seem to make it.

Thank you for the help

+6  A: 

Are you calling StreamWriter.Close() or Flush()?

itsmatt
thank you that is exactly what I forgot
jmein
@itsmatt: I'm wondering why Close/Flush is even required
sixlettervariables
Cause the AutoFlush property might be set to false.
MagicKat
@MagicKat: then you obviously wouldn't forget to call Flush, because AutoFlush must be explicitly disabled...I'd hope.
sixlettervariables
@itsmatt: I am looking at close in reflector, but I am not seeing a call to flush ...
MagicKat
StreamWriter.Dispose calls Flush (as per reflector), which is called by Close.
sixlettervariables
@sixlettervariables - autoflush, I believe, defaults to false.
itsmatt
@sixlettervariable: doh ... the Dispose I was clicking on was taking me to TextWriter. My bad lol
MagicKat
+3  A: 

Be sure you wrap your StreamWriter in a using-block, or are careful about your explicit management of the resource's lifetime.

using (StreamWriter writer = new StreamWriter(@"somefile.txt"))
{
    // ...
    writer.WriteLine(largeAmountsOfData);
    // ...
}
sixlettervariables
A: 

Make sure that you are calling .Flush()

MagicKat