SaaDwTk 0 Newbie Poster

I have created a function to add the text from a file inside another text file, if I had to add only one block of code it would be okay, but the problem is when I have to insert more than one block into a same source file.

Example:
FileDest1.txt, FileToCopy.txt, 10)
FileDest1.txt, FileToCopy.txt, 25)
FileDest1.txt, FileToCopy.txt, 40)

So lets say that in this example, at line 25 will be inserted a block with 30 lines, so the total lines from the FileDest1 file will increase, and line 40 will be moved to line 70 (because the 30 extra lines was added in the whole file).

I have tried to begin changing from the bottom to the top but didn't worked either.

Do you know how can I solve this?

This is the code made by me:

    Public Function insertCode(filePath As String, copyFile As String, noLine As Integer)
        Dim i As Integer = 0
        Dim y As Integer = 0
        Dim allLines As New List(Of String)(IO.File.ReadAllLines(filePath))
        Dim allLinesMod As New List(Of String)(IO.File.ReadAllLines(copyFile))

        Using writer As StreamWriter = New StreamWriter(filePath)

            While (i < noLine)
                writer.WriteLine(allLines(i))
                i += 1
            End While

            While (y < allLinesMod.Count)
                writer.WriteLine(allLinesMod(y))
                y += 1
            End While

            While (i < allLines.Count)
                writer.WriteLine(allLines(i))
                i += 1
            End While
        End Using

        Return Nothing
    End Function
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.