|
Question : File Copying through CopyFileEx of kernel32.dll in vb.net
|
|
I am trying to copy files in vb.net through a kernel32.dll Function CopyFileEx, because I want to show progress of File Copying and also Cancellation of Copy process. I copied the code from http://www.codenotes.com/do/articles/article?articleID=528 this code starts copying file but then it hangs up and no progress is shown, neither file is coppied. If any one know the solution to the problem then please let me know.
|
|
Answer : File Copying through CopyFileEx of kernel32.dll in vb.net
|
|
This code will copy files showing the progress. You can use wild cards here
Public Class Form1 Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code " #End Region
Private Structure SHFILEOPSTRUCT Dim hWnd As Integer Dim wFunc As Integer Dim pFrom As String Dim pTo As String Dim fFlags As Short Dim fAborted As Boolean Dim hNameMaps As Integer Dim sProgress As String End Structure
Private Const FO_DELETE As Short = &H3S Private Const FO_COPY As Short = &H2S Private Const FO_MOVE As Short = &H1S Private Const FO_RENAME As Short = &H4S Private Const FOF_ALLOWUNDO As Short = &H40S Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" _ (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim SHFileOp As SHFILEOPSTRUCT
With SHFileOp .pFrom = "c:\a\*.mdb" .pTo = "c:\temp\download" .wFunc = FO_COPY End With 'perform file operation SHFileOperation(SHFileOp) MsgBox("The Folder '" & SHFileOp.pFrom & "' has been Copied To : " & SHFileOp.pTo, MsgBoxStyle.Information + MsgBoxStyle.OKOnly, System.Reflection.Assembly.GetExecutingAssembly.GetName.Name) End Sub End Class
|
|
|