Tech Off Thread

3 posts

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

Back to Forum: Tech Off
  • complete

    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?

     

  • lensman

    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.

  • 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.