BP Forums
How do you programatically open a file in c# to append? - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: C#.NET (Visual C# 2010/2008) (https://bpforums.info/forumdisplay.php?fid=20)
+---- Thread: How do you programatically open a file in c# to append? (/showthread.php?tid=699)



How do you programatically open a file in c# to append? - complete - 11-17-2012

How do you programatically open a file in c# to append?

I tried searching online for an example and so far I have not found anything.

There is System.IO.StreamWriter and there is System.IO.StreamReader but there is no StreamAppend. Is there some way to use StreamWriter without overwritting the content of the existing file? Is there some way to use System.IO.Stream with some sort of appending criteria?


Re: How do you programatically open a file in c# to append? - Snake_eyes - 11-17-2012

If you want to simply write text by appending it to the existing file just create a new stream writer
Code:
StreamWriter sr = new StreamWriter("path to file", true);

Whent set to true it will append the text to the existing file. If the file does not exist the StreamWriter wil create a new file