Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

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

Back to Forum: Tech Off
  • User profile image
    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?

     

  • User profile image
    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.

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

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.