Re: Append mode in write operation

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Append mode in write operation
    ... overwriting the current content). ... believe the append mode is defined with different parameters from the ... What are the correct parameters to define the "append" ...
    (microsoft.public.dotnet.general)
  • Re: Capture console output to file ?
    ... In article, Jeffrey Ross wrote: ... > If you want to append to these files rather than overwriting them use ... > If you want both stdout and stderr in the same file (noting that they may ...
    (linux.redhat)
  • Append to the end of file when "write"
    ... append the new content to the end of the file (instead of ... overwriting the current content). ... FileStream lStream = ... correct parameters. ...
    (microsoft.public.dotnet.general)
  • Re: Append to the end of file when "write"
    ... append the new content to the end of the file (instead of ... overwriting the current content). ... FileStream lStream = ... The FileInfo class exposes an AppendText method, ...
    (microsoft.public.dotnet.general)
  • Re: path keeps bloating with repeated entries on invoking subshells
    ... I thought this was the right way to go since I only append to the ... systemwide path settings without overwriting anything as a user. ... duplicate entries (I guess a side-effect of appending the $path at the ...
    (comp.os.linux.misc)