Jimbo99999
asked on
VB.Net - IO.StreamWriter File Display Size
Good Day Experts!
I have a little project that writes out data to a csv file via a StreamWriter. When I go to the directory that the file is created in, the size of the file does not increase as the file grows. I have to hit View --> Refresh.
Is there a way to have the size change dynamically so I don't have to hit View --> Refresh?
Thanks,
jimbo99999
I have a little project that writes out data to a csv file via a StreamWriter. When I go to the directory that the file is created in, the size of the file does not increase as the file grows. I have to hit View --> Refresh.
Is there a way to have the size change dynamically so I don't have to hit View --> Refresh?
Thanks,
jimbo99999
That's due to Windows, not your application. There may be a way to hook into Explorer's API (if it has one), but I suspect it would be more trouble than it's worth. For that matter, you might just do a SendKeys call to the Explorer window and send an F5 key press. You would need the SetForegroundWindow Win API method. You would also need a way of identifying the target Explorer window (if you have multiples open). I think for this you would want to spawn the Explorer window yourself (from code) so that you can capture it's window handle--which SetForegroundWindow would need.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the replies.
At the bottom of my Do While Loop I Have:
out.WriteLine(DTLString)
You are suggesting I flush?
jimbo99999
At the bottom of my Do While Loop I Have:
out.WriteLine(DTLString)
You are suggesting I flush?
jimbo99999
You still need the WriteLine() there to write out the data. The output is normally buffered (i.e. held in memory rather than being immediately committed to disk), so adding a out.Flush() call periodically inside your loop should force the content to disk and allows Windows to update to show the current actual size.
You don't want to use Flush() on every iteration though, pick some sensible period (say once for every 10% of iterations)
You don't want to use Flush() on every iteration though, pick some sensible period (say once for every 10% of iterations)
Doh! I forgot about that. (No more questions at 1 AM for me.) carl_tawn is correct; disregard my previous comment.
ASKER
Ok, up above my loop where I define the Streamwriter here is what I am trying:
out = My.Computer.FileSystem.Ope nTextFileW riter(File Name, False)
out.AutoFlush = True
It is incrementing the size now with no View --> Refresh.
Do you see any issues with doing it this way?
Thanks,
jimbo99999
out = My.Computer.FileSystem.Ope
out.AutoFlush = True
It is incrementing the size now with no View --> Refresh.
Do you see any issues with doing it this way?
Thanks,
jimbo99999
No, that's fine and dandy. It will have the same effect as doing it manually.
ASKER
Thanks for the help. Until today I never knew what .Flush was for.
Have a good day,
jimbo99999
Have a good day,
jimbo99999