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

Dear
Do Something like this.. you can convert your code to C# easily

Public Shared Function ReadBillFile(ByVal Filename As String) As String
        Try
            Dim sr As StreamReader
            Dim i, linecount As Integer

            sr = File.OpenText(Filename)
            Dim contents As ArrayList
            Dim finalfile As String
            While Not (sr.EndOfStream)
                linecount += 1
                contents(linecount) += sr.ReadLine
            End While
                        sr.Close()

            For i = 1 To contents.Count - 1
                finalfile += contents(i)
            Next
           
           Return finalfile 

        Catch ex As IOException
            MsgBox(ex.Message)
        End Try
    End Function

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

Mark as sovled, if it helps you
Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.