Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Merging Two Text Files
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00948382
Message ID:
00948980
Views:
18
This message has been marked as the solution to the initial question of the thread.
>Good afternoon to ol!!!
>
>I would just like to know how to merge two text files into one. Using DOS command is simply:
>
>Copy File1.txt+File2.txt File3.txt
>
>In DotNET I tried:
>
> File.Copy(cPath & "File1.txt + " & cPath & "File2.txt", cPath & "File3.txt")
>
>... and ...
>
> File.Copy(cPath & "File1.txt" + cPath & "File2.txt", cPath & "File3.txt")
>
>... but both commands just gave out an error. Any ideas on how this can be achieved?
>
>Actually, what I am trying to achieve here is to append a line into File2.txt. File1 is a header file that contains summary information regarding the records in file2. If anyone know how I can insert a line of text to the very 1st line of the text file, that would be even better!
>
>Thanx! in advance!!!


this is a little example
    Sub AppendText()
        Dim Filename As String = "yourFileName.txt"
        Dim TextToAdd As String
        Dim strWriter As System.IO.StreamReader

        'open your file in append mode for recieving the content of the other file
        Dim Fs As FileStream = New FileStream(Filename, FileMode.Append, FileAccess.Write, FileShare.None)
        'opening the second file which has the text you want to add to the first file
        strWriter = File.OpenText("c:\temp\test.txt")
        'reading the text and puting it to a var
        TextToAdd = strWriter.ReadToEnd()
        'close the second file
        strWriter.Close()
        'appending the second file's text to the first one
        Dim SwFromFileStream As StreamWriter = New StreamWriter(Fs)
        SwFromFileStream.Write(TextToAdd)
        SwFromFileStream.Flush()
        SwFromFileStream.Close()
    End Sub
i am not sure if this is what you want
.......
DO WHILE .T.
      ME.Work()
ENDDO
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform