Writing to file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a text file that contains 5 lines, I want to write to it: removing
the first line and replacing it with something else, while keeping the other
lines.

Can someone tell me how it could be done?

Its a silly question but I am a new developer in C#.

Thank you.
 
hi,


The safest aproach is to create a temp file ( using Path.GetTempPath/
Path.GetTempFileName ) and read each lie of the file, replace as needed,
write the others without change and then use File.Copy to override the
original

Just remember ot close the original before doing the copy ;)

cheers,
 
Back
Top