469,902 Members | 1,926 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,902 developers. It's quick & easy.

What is the easiest way to open a textfile for append or create it for text append?

I would like to append text to a file which might exist or not.

What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?
May 22 '07 #1
3 2407
"Wolfgang Meister" <wm******@hotmail.comwrote in message
news:46***********************@newsspool1.arcor-online.net...
>I would like to append text to a file which might exist or not.

What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?
Just do it -

FileStream fs = new FileStream("your_path", FileMode.Append);

.... or were you looking for something else?

-cd
May 22 '07 #2
Something like this for a file with full path stored in 'path' variable:

StreamWriter writer = null;

if (File.Exists(path))

{

writer = new StreamWriter(path, true);

}

else

{

writer = new StreamWriter(File.Create(path));

}

writer.WriteLine("Nex line or whatever else"));

writer.WriteLine("Another line or whatever");

writer.Close();

Michael

"Wolfgang Meister" <wm******@hotmail.comwrote in message
news:46***********************@newsspool1.arcor-online.net...
>I would like to append text to a file which might exist or not.

What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?


May 22 '07 #3
On May 22, 3:28 pm, wmeis...@hotmail.com (Wolfgang Meister) wrote:
I would like to append text to a file which might exist or not.

What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?
I guess that:

File.AppendAllText(string path, string content);

May 23 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Peter Proost | last post: by
3 posts views Thread by DG | last post: by
8 posts views Thread by Flyzone | last post: by
10 posts views Thread by silverburgh.meryl | last post: by
lifeisgreat20009
1 post views Thread by lifeisgreat20009 | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.