با سلام
میتونید از سورسی که براتون نوشتم استفاده کنید :
Imports System.IO
Public Class Form1
Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
Dim ofd As New OpenFileDialog With {.Filter = "All Files|*.*"}
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
txtFileDes.Text = ofd.FileName
txtFileSaveWhere.Text = ""
lblFileSize.Text = Math.Round(CInt(New FileInfo(ofd.FileName).Length.ToString) / 1024, 3) & " کیلو بایت "
End If
End Sub
Private Sub btnWhereToSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWhereToSave.Click
Dim sfd As New FolderBrowserDialog
If txtFileDes.Text.Length > 0 AndAlso sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
txtFileSaveWhere.Text = sfd.SelectedPath & "\" & New FileInfo(txtFileDes.Text).Name
End If
End Sub
Private Sub SaveBinaryFile(ByVal strFilename As String, ByVal bytesToWrite() As Byte)
Dim position As Integer = 0
Dim BufferSize As Integer = 4096
ProgressBar1.Value = 0
Using fsNew As FileStream = New FileStream(strFilename, FileMode.Create, FileAccess.Write)
Do
Dim intToCopy As Integer = Math.Min(BufferSize, bytesToWrite.Length - position)
Dim buffer(intToCopy - 1) As Byte
Array.Copy(bytesToWrite, position, buffer, 0, intToCopy)
fsNew.Write(buffer, 0, buffer.Length)
ProgressBar1.Value = ((position / bytesToWrite.Length) * 100)
lblAction.Text = "در حال کپی کردن فایل"
ProgressBar1.Refresh()
Application.DoEvents()
position += intToCopy
Loop While position < bytesToWrite.Length
ProgressBar1.Value = 0
lblAction.Text = ""
End Using
End Sub
Private Function ReadBinaryFile(ByVal strFilename As String) As Byte()
Dim position As Integer = 0
Dim bufferSize As Integer = 4096
Dim bytes() As Byte
ProgressBar1.Value = 0
Using fsOpen As FileStream = New FileStream(strFilename, FileMode.Open)
ReDim bytes((fsOpen.Length) - 1)
Do
If (position + bufferSize) > fsOpen.Length Then
fsOpen.Read(bytes, position, fsOpen.Length - position)
Exit Do
Else
fsOpen.Read(bytes, position, bufferSize)
End If
ProgressBar1.Value = ((position / fsOpen.Length) * 100)
lblAction.Text = "درحال خواندن فایل ..."
ProgressBar1.Refresh()
Application.DoEvents()
position += bufferSize
Loop
ProgressBar1.Value = 0
lblAction.Text = "آماده کپی کردن فایل"
End Using
Return bytes
End Function
Private Sub btnCopyFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopyFile.Click
If txtFileDes.Text.Length > 0 AndAlso txtFileSaveWhere.Text.Length > 0 Then
SaveBinaryFile(txtFileSaveWhere.Text, ReadBinaryFile(txtFileDes.Text))
End If
End Sub
End Class
موفق باشید./