Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • Leaders
Posted

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);
}

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...