
Summary
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.
Introduction
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.
Description
SplitMerge.VB
This class has two primary methods SplitFile
and MergeFile
.
Both these methods are thread safe and can be called as background threads
Events
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")
Else
MsgBox("File Split process Failed" & NEWLINE & ErrorMessage)
End If
ResetControls()
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.