Xarzu Posted November 17, 2012 Posted November 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? Quote
Leaders snarfblam Posted November 17, 2012 Leaders Posted November 17, 2012 One (or more) of the FileStream constructors accepts a FileMode argument, which allows you to specify FileMode.Append. Once you've created the FileStream, you can create a StreamWriter with the FileStream. Depending on what you're doing, you might also be able to use one of the handy convenience methods of the System.IO.File class. void AppendToLog(string text) { File.AppendAllText(Program.LogPath, text); } Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.