0

I am want saving data in my txt file area but when I am try my below code then it's going saving in my txt file all line end area.

Actually my file available more then 4000 line so I am always want new line going saving first line area.

Please help me how I am saving data in first line area always.

below code only saving all line after mean end the area but I am want start line area going saving data.

string myFile = @"C:\\live\\dadata.txt";
StreamReader osr = new StreamReader(myFile);
string myText = osr.ReadToEnd();
osr.Close();
osr.Dispose();
StreamWriter osw = new StreamWriter(myFile);
osw.Write(myText + Environment.NewLine + workd.Text);
osw.Close();
osw.Dispose();
Sergii Zhevzhyk
  • 4,074
  • 22
  • 28
  • 2
    Can you please state your question more clearly? I'm having a hard time following what you are trying to accomplish. – The Sharp Ninja Dec 11 '15 at 17:32
  • think he is saying that his file saves all on 1 line and wants it to do a new line each time – KratosMafia Dec 11 '15 at 17:35
  • http://stackoverflow.com/questions/19315921/c-sharp-save-to-multiple-lines-in-a-text-file http://stackoverflow.com/questions/9236584/c-sharp-how-to-write-multiple-lines-in-a-text-file – KratosMafia Dec 11 '15 at 17:37
  • Possible duplicate of [How to prepend a header in a text file](http://stackoverflow.com/questions/10511628/how-to-prepend-a-header-in-a-text-file) – dbc Dec 14 '15 at 06:31

1 Answers1

0

I believe what you need is the Seek function of the StreamWriter to set the position of the cursor. An example of how that might work is below.

'set the file pointer to the start of the file
  streamReader.BaseStream.Seek(offset:=0, _ 
        origin:=SeekOrigin.Begin) 

I got the above from here. There are many places you can learn about Seek though.

I haven't personally tried it, but I have used Seek before in different languages, and seek is what you want, now you just need the specific syntax in the language of your choice.

Owen Ivory
  • 244
  • 1
  • 9