PC Review


Reply
Thread Tools Rate Thread

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

 
 
Wolfgang Meister
Guest
Posts: n/a
 
      22nd May 2007
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?


 
Reply With Quote
 
 
 
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      22nd May 2007
"Wolfgang Meister" <(E-Mail Removed)> wrote in message
news:4653527e$0$23131$(E-Mail Removed)...
>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


 
Reply With Quote
 
 
 
 
Michael Rubinstein
Guest
Posts: n/a
 
      22nd May 2007
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" <(E-Mail Removed)> wrote in message
news:4653527e$0$23131$(E-Mail Removed)...
>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?
>
>



 
Reply With Quote
 
daniel.cigic@googlemail.com
Guest
Posts: n/a
 
      23rd May 2007
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);

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the easiest way to convert unix/linux text files to DIS/Win text files? Eugen Austermann Windows XP Help 9 22nd Dec 2007 03:22 AM
What is the easiest way to convert unix/linux text files to DIS/Win text files? Eugen Austermann Windows XP General 0 21st Dec 2007 05:18 PM
Easiest way to remove text from a cell that has text and numbers? cram.it.clownie@gmail.com Microsoft Excel Misc 2 17th Aug 2006 06:07 PM
What is the easiest way to create an intranet with FrontPage? aspirin2004 Microsoft Frontpage 3 16th Apr 2004 11:58 PM
append textfile to a table Koos Koets Microsoft Access Getting Started 0 11th Jul 2003 08:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:38 AM.