0

Hi,

Actully i wanted to merge two txt files into one txt file. (i.e. second file has to be appended to the first file). please give me some solution for my problem. I am new to vb.net, so pls elaborate the solution.

Thanks in advance.

2
Contributors
1
Reply
11
Views
8 Years
Discussion Span
Last Post by robert_c_guy
1

VB.Net makes a task like that quite simple:

Public Sub text_combine( _
        ByVal path_to_read_file As String, _
        ByVal path_to_append_file As String _
    )
        System.IO.File.AppendAllText( _
            path_to_append_file, _
            System.IO.File.ReadAllText(path_to_read_file) _
        )
    End Sub

A little error checking may prevent hangups:

Public Function text_combine( _
        ByVal path_to_read_file As String, _
        ByVal path_to_append_file As String _
    ) As Boolean
        If ( _
            (IO.File.Exists(path_to_read_file)) _
            And (IO.File.Exists(path_to_append_file)) _
        ) Then
            Try
                System.IO.File.AppendAllText( _
                    path_to_append_file, _
                    System.IO.File.ReadAllText(path_to_read_file) _
                )
                text_combine = True
            Catch ex As Exception
                text_combine = False
            End Try
        Else
            text_combine = False
        End If
    End Function
Votes + Comments
Nice Code.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.