I have been trying to write some strings to the notepad.
I have successfullly written the first string , however when I try to add another string,It always over writes the first string I have written.Can you tell me a way where I can write strings to the next line all the time I want to write to the note pad


//use the WriteLine method of the StreamWriter class...like so...

using (StreamWriter mywriter = new StreamWriter(//your file path here))
mywriter.WriteLine("LINE 1");
mywriter.WriteLine("LINE 2");

//or you could put values in an array and write each one using a foreach loop...

string[] lines = { "LINE 1", "LINE 2", "LINE 3" };

            using (StreamWriter mywriter = new StreamWriter(//your file path here))
                foreach (string s in lines)

Hope it helps

Here you have simple examples of using StreamWriter, which is in your case by far best object to use.
And here you can read about StreamWriter class. Its good to know which metods and properties to use with this object.
Hope it helps,

The problem that i am facing is , everytime I write using streamwriter , It overwrites the existing line in the note pad ,But doesnt start from the next line.How should I tell the stream writer from where it should start.I want each input to be in a seperate line.

If I understand you, you would like to write into a file constantly, every time simply adding lines on the end of the current text? Is that correct?

If so, you can use File.AppendText method. This how:

using (StreamWriter sw = File.AppendText(path)) 
            sw.WriteLine("is Extra");

Hope this helps,

What problems? You cannot access to this class?
Add a new namespace "IO" (using System.IO;).

If this is not it, please tell me exactly which problem is it.

Yes I mind. Post YOUR code and YOUR problem in a different thread. We all be glad to help:)

Edited 5 Years Ago by ddanbe: n/a

Will do that, and I know I should read the code of conduct, so I probably will now. Thanks

before you leave, mark this thread as answered (in case if you got th answer on the thread topic).
best regards

This article has been dead for over six months. Start a new discussion instead.