Append to the end of file when "write"

Append to the end of file when "write"

am 15.10.2007 04:55:22 von Fir5tSight

I want to write to an output file, "C:\\temp\\debug.txt": If the file
exists, append the new content to the end of the file (instead of
overwriting the current content). If the file doesn't exist, create
the file and write from the beginning.

Therefore, I want to code this like below:

FileInfo lFile = new FileInfo("C:\\temp\\debug.txt");

if (lFile.Exists)
{
// What's the syntax to append new content (instead of
overwriting the existing content?
FileStream lStream =
lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);

}
else
{
FileStream lStream =
lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
}

I believe the append mode is defined at the "lFile.Open" line with the
correct parameters. Thanks!

Re: Append to the end of file when "write"

am 15.10.2007 05:06:02 von pvdg42

"Curious" wrote in message
news:1192416922.311543.194130@k35g2000prh.googlegroups.com.. .
>I want to write to an output file, "C:\\temp\\debug.txt": If the file
> exists, append the new content to the end of the file (instead of
> overwriting the current content). If the file doesn't exist, create
> the file and write from the beginning.
>
> Therefore, I want to code this like below:
>
> FileInfo lFile = new FileInfo("C:\\temp\\debug.txt");
>
> if (lFile.Exists)
> {
> // What's the syntax to append new content (instead of
> overwriting the existing content?
> FileStream lStream =
> lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
>
> }
> else
> {
> FileStream lStream =
> lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
> }
>
> I believe the append mode is defined at the "lFile.Open" line with the
> correct parameters. Thanks!
>


The FileInfo class exposes an AppendText method, which you may find useful:

http://msdn2.microsoft.com/en-us/library/system.io.fileinfo. appendtext(VS.80).aspx