468,783 Members | 1,645 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

Is there any way for System.IO.StreamWriter Write method to write out part of the string to file. such as if the machine is shut down half way through? or does the file not actually exist until the entire write is completed successfully.

Is there any way for System.IO.StreamWriter Write method to write out part
of the string to file. such as if the machine is shut down half way through?
or does the file not actually exist until the entire write is completed
successfully.
Nov 17 '05 #1
2 3525
Hello

It's not .NET Framework issue. It depends on system you are running on. And
I guess, that you will have a broken file if you will restart your system in
the middle of file writing.

You can write your file to a temporary folder. And when the whole file will
be written you can move it to desired place. If system will be shutdown in
this moment, then you will have a broken file in temporary directory. But
you can always clean up it on systems startup. But, it will work only if
your temporary folder is resides on the same partition as your desired
location, so file moving can be done with one shot.


--
With best regards,
Andrew

http://www.codeproject.com/script/pr...asp?id=1181072
"Daniel" <so*******************@yahoo.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
Is there any way for System.IO.StreamWriter Write method to write out part
of the string to file. such as if the machine is shut down half way through? or does the file not actually exist until the entire write is completed
successfully.

Nov 17 '05 #2
If the file is just text it will be fine. You can call flush after you write
each line which commits everything in the buffer. Obviously the file
wouldn't be complete and im pretty sure it will throw an exception if someone
were to shutdown the pc while this was running.

"Andrew Kirillov" wrote:
Hello

It's not .NET Framework issue. It depends on system you are running on. And
I guess, that you will have a broken file if you will restart your system in
the middle of file writing.

You can write your file to a temporary folder. And when the whole file will
be written you can move it to desired place. If system will be shutdown in
this moment, then you will have a broken file in temporary directory. But
you can always clean up it on systems startup. But, it will work only if
your temporary folder is resides on the same partition as your desired
location, so file moving can be done with one shot.


--
With best regards,
Andrew

http://www.codeproject.com/script/pr...asp?id=1181072
"Daniel" <so*******************@yahoo.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
Is there any way for System.IO.StreamWriter Write method to write out part
of the string to file. such as if the machine is shut down half way

through?
or does the file not actually exist until the entire write is completed
successfully.


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by lawrence | last post: by
12 posts views Thread by R | last post: by
13 posts views Thread by Stumped and Confused | last post: by
28 posts views Thread by Jon Davis | last post: by
20 posts views Thread by djc | last post: by
7 posts views Thread by Mark Rae | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.