Click here to Skip to main content
13,300,002 members (57,428 online)
Click here to Skip to main content
Add your own
alternative version


46 bookmarked
Posted 9 Aug 2002

File Split & Merge Tool

, 9 Aug 2002
Rate this:
Please Sign up or sign in to vote.
This tool is used to split large files into smaller chunks and merge them back into a single file.

Sample Image - File_Split___Merge_Tool.jpg


This tool is used to split large files into smaller chunks of your choice and merge them back into single file. This is extremely useful when copying files into floppies or while transferring files over network.


This project consists of a class SplitMerge.vb and a user interface to test the class. Source code is provided as a VS.NET project, so you can download the source and build it with current version of VS.NET. I created and tested this under VS.NET with SP2 under Windows 2000.

This project demonstrates the usage of file streams, threading and events in VB.NET.



This class has two primary methods SplitFile and MergeFile.

  • SplitFile

    Splits files into smaller chunk files.

    • FileName: File name to split with full path
    • OutputPath: Output folder name where the chunk files will be created. Chunk files will be created with the same name as input file with suffix of sequence number (e.g.: bigfile.exe.001)
    • DeleteFileAfterSplit: Boolean value indicating, whether to delete the input file after splitting.
    • ChunkSize: Long value indicating the chunk size in bytes.
  • MergeFile

    Merges all the chunk files into one file.

    • FileName: First chunk file name with full path or the file name with full path (In this case c:\bigfile.exe.001 or c:\bigfile.exe)
    • OutputPath: Output folder name where the merged file will be created
    • DeleteFilesAfterMerge: Boolean value indicating, whether to delete the chunk file after merge.

Both these methods are thread safe and can be called as background threads


This class has 3 events.

  • FileSplitCompleted  - This event is raised after the split process is completed
  • FileMergeCompleted - This event is raised after the merge process is completed
  • UpdateProgress - This event is raised to notify the client about the progress. Raised after each chunk file is created.

Using SplitMerge class

Add a form to your project. Declare SplitMerge class with events.

Private WithEvents _FileSplitMerge As New SplitMerge() 

Declare a thread to call the Split and Merge Methods

Private backgroundThread As System.Threading.Thread

See the demo for other controls 

Calling Split process

Private Sub SplitFile()
    With _FileSplitMerge.ChunkSize = txtChunkSize.Text
        .FileName = txtFileName.Text
        .OutputPath = txtOutputFolder.Text
        .DeleteFileAfterSplit = chkOption.Checked
        backgroundThread = New _ 
         Threading.Thread(AddressOf .SplitFile)backgroundThread.Start()
    End With
End Sub

After the split process is completed, it will raise the FileSplitCompleted event.

FileSplitCompleted event will return an ErrorMessage, in case of an error it will return the error message else an empty string.

Private Sub _FileSplitMerge_FileSplitCompleted(ByVal _ 
          ErrorMessage As String) Handles _FileSplitMerge.FileSplitCompleted
    If ErrorMessage = "" Then
        MsgBox("File Split process completed")
        MsgBox("File Split process Failed" & NEWLINE & ErrorMessage)
    End If
End Sub

So check for the ErrorMessage to display appropriate message.

Calling Merge procedure

Private Sub MergeFiles()
    With _FileSplitMerge.FileName = txtFileName.Text
        .OutputPath = txtOutputFolder.Text
        .DeleteFilesAfterMerge = chkOption.Checked
        backgroundThread = New _ 
          Threading.Thread(AddressOf .MergeFile)backgroundThread.Start()
    End With
End Sub

Events are the same as Split process.

Demo comes with a fully functional example.

Notes & ToDo features

I would like to enhance this further by adding Crypt, Compression and password functionalities in next version.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Sreenivas Vemulapalli
Web Developer
United States United States
Working as consultant in Client/server,Web Development, Automation areas using C#,Vb,,,Sql Server,Xml,Html&Dhtml etc..
Looking for a challenging project in .NET

You may also be interested in...


Comments and Discussions

QuestionProblem with large files Pin
Muthuraj81422-Dec-11 21:39
memberMuthuraj81422-Dec-11 21:39 
QuestionSpliting files with different extensions in Pin
Pavi345612-Jul-11 4:42
memberPavi345612-Jul-11 4:42 
GeneralGreat! Pin
Jesse Garcia28-Jul-08 21:43
memberJesse Garcia28-Jul-08 21:43 
GeneralI want to know.... [modified] Pin
tj_istar9-Aug-07 3:42
membertj_istar9-Aug-07 3:42 
GeneralMessage Closed Pin
27-Jun-07 19:14
memberwinnovative27-Jun-07 19:14 
GeneralRe: Commercial Split/Merge Pin
The JZ23-Feb-08 8:53
memberThe JZ23-Feb-08 8:53 
QuestionHow do i send the split files over LAN? Pin
red_kops30-Aug-05 8:56
sussred_kops30-Aug-05 8:56 
GeneralDoesn't work for large files Pin
luke73489728924-Aug-05 10:09
memberluke73489728924-Aug-05 10:09 
GeneralRe: Doesn't work for large files Pin
luke73489728924-Aug-05 10:26
memberluke73489728924-Aug-05 10:26 
Generalslow but good Pin
Ahmed ceder25-Sep-04 12:17
memberAhmed ceder25-Sep-04 12:17 
GeneralRe: slow but good Pin
eRRaTuM30-Mar-06 5:21
membereRRaTuM30-Mar-06 5:21 
GeneralPDF File Merge Pin
Zulfikar Ali4-Oct-02 10:37
memberZulfikar Ali4-Oct-02 10:37 
GeneralRe: PDF File Merge Pin
Sreenivas Vemulapalli4-Oct-02 12:26
memberSreenivas Vemulapalli4-Oct-02 12:26 
Generaltry this Pin
Sreenivas Vemulapalli4-Oct-02 12:29
memberSreenivas Vemulapalli4-Oct-02 12:29 
GeneralRe: try this Pin
Zulfikar Ali4-Oct-02 12:50
memberZulfikar Ali4-Oct-02 12:50 
GeneralSpeed enhancement Pin
Paul A. Howes12-Aug-02 3:47
memberPaul A. Howes12-Aug-02 3:47 
GeneralRe: Speed enhancement Pin
Sreenivas Vemulapalli12-Aug-02 13:26
memberSreenivas Vemulapalli12-Aug-02 13:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 10 Aug 2002
Article Copyright 2002 by Sreenivas Vemulapalli
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid