Append mode in write operation

Append mode in write operation

am 15.10.2007 05:01:02 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).

Therefore, I want to code this like below:


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


if (lFile.Exists)
{

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


}

However, it doesn't work because It overwrites the existing content. I
believe the append mode is defined with different parameters from the
ones I use. What are the correct parameters to define the "append"
type of write mode?

Thanks!

Re: Append mode in write operation

am 15.10.2007 06:51:26 von Guffa

Curious wrote:
> 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).
>
> Therefore, I want to code this like below:
>
>
> FileInfo lFile = new FileInfo("C:\\temp\\debug.txt");
>
>
> if (lFile.Exists)
> {
>
> FileStream lStream =
> lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
>
>
> }
>
> However, it doesn't work because It overwrites the existing content. I
> believe the append mode is defined with different parameters from the
> ones I use. What are the correct parameters to define the "append"
> type of write mode?
>
> Thanks!
>

Use FileMode.Append. You don't have to check if the file exists, if it
doesn't exist it will be created.

--
Göran Andersson
_____
http://www.guffa.com

Re: Append mode in write operation

am 15.10.2007 15:50:59 von Fir5tSight

Thanks Göran! It works!