Sunday, August 19, 2007

Finding the Size of a file while Writing when using StreamWriter

In VB 6, you could always use LOF() to find the length of the file you were writing; however, in VB.NET or C# is not as obvious.

Dim s As StreamWriter = New StreamWriter(filename)
Dim offsetPosition as Long = s.BaseStream.Length

One thing to note, you will have to do the Flush before using the length property or you will not get accurate results. You can also set the AutoFlush property on the StreamWriter object.

For more info, see:

No comments: