how to delete the last line of the text file using c#

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2009
Posts: 1
Reputation: imad442 is an unknown quantity at this point 
Solved Threads: 0
imad442 imad442 is offline Offline
Newbie Poster

how to delete the last line of the text file using c#

 
0
  #1
Jan 19th, 2009
how to delete the last line of the text file using c#.

i applicaiton create a text file ..with 2 empty lines at the end of the File

now i just require a method which open the text file and delete the last 2 lines of the text File ..the code in c# is preferred

yaar please help me out with this on ..

thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 92
Reputation: reach_yousuf is an unknown quantity at this point 
Solved Threads: 15
reach_yousuf reach_yousuf is offline Offline
Junior Poster in Training

Re: how to delete the last line of the text file using c#

 
0
  #2
Jan 20th, 2009
Dear
Do Something like this.. you can convert your code to C# easily

  1. Public Shared Function ReadBillFile(ByVal Filename As String) As String
  2. Try
  3. Dim sr As StreamReader
  4. Dim i, linecount As Integer
  5.  
  6. sr = File.OpenText(Filename)
  7. Dim contents As ArrayList
  8. Dim finalfile As String
  9. While Not (sr.EndOfStream)
  10. linecount += 1
  11. contents(linecount) += sr.ReadLine
  12. End While
  13. sr.Close()
  14.  
  15. For i = 1 To contents.Count - 1
  16. finalfile += contents(i)
  17. Next
  18.  
  19. Return finalfile
  20.  
  21. Catch ex As IOException
  22. MsgBox(ex.Message)
  23. End Try
  24. End Function

Note : After that, Edit the existing file and save the finalfile data in it.

Mark as sovled, if it helps you
Regards
Last edited by reach_yousuf; Jan 20th, 2009 at 10:26 am.
Yousuf
Software Developer
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3008 | Replies: 1
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC