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
Jimbo99999Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
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.
0
Carl TawnSystems and Integration DeveloperCommented:
How are you writing to your file? Have you tried periodically flushing the stream during the write process?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimbo99999Author Commented:
Thanks for the replies.

At the bottom of my Do While Loop I Have:

out.WriteLine(DTLString)

You are suggesting I flush?

jimbo99999
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Carl TawnSystems and Integration DeveloperCommented:
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)
0
käµfm³d 👽Commented:
Doh! I forgot about that. (No more questions at 1 AM for me.) carl_tawn is correct; disregard my previous comment.
0
Jimbo99999Author Commented:
Ok, up above my loop where I define the Streamwriter here is what I am trying:

out = My.Computer.FileSystem.OpenTextFileWriter(FileName, 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
0
Carl TawnSystems and Integration DeveloperCommented:
No, that's fine and dandy. It will have the same effect as doing it manually.
0
Jimbo99999Author Commented:
Thanks for the help.  Until today I never knew what .Flush was for.

Have a good day,
jimbo99999
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.