Tech Off Thread

3 posts

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

Back to Forum: Tech Off
  • User profile image

    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?


  • User profile image

    Using intellisense only:

    System.IO.FileStream fs = System.IO.File.Open("filename", System.IO.FileMode.Append);

    is one of the many ways you could do it.

  • User profile image
    Sven Groot

    If you want to use StreamWriter, simply use the StreamWriter(string path, bool append) constructor:

    using( StreamWriter writer = new StreamWriter("filename", true) )
        // Append stuff here.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.