Mit File.Copy() geht's nicht, aber du kannst selber die Daten kopieren in einer Schleife, die CopyFileEx() API benutzen wie unten, oder SHFileOperation für den üblichen Windows-Dialog.
(Leicht abgewandlete Versions des VB6 Codes aus Tipps&Tricks)
Public Const PROGRESS_CANCEL = 1
Public Const PROGRESS_CONTINUE = 0
Public Const PROGRESS_QUIET = 3
Public Const PROGRESS_STOP = 2
Public Const COPY_FILE_FAIL_IF_EXISTS = &H1
Public Const COPY_FILE_RESTARTABLE = &H2
Public Declare Auto Function CopyFileEx Lib "kernel32.dll" ( _
ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal lpProgressRoutine As Fortschritt, _
ByVal lpData As Integer, _
ByRef pbCancel As Integer, _
ByVal dwCopyFlags As Integer) As Integer
Public bCancel As Integer
Public Delegate Function Fortschritt( _
ByVal TotalFileSize As Long, _
ByVal TotalBytesTransferred As Long, _
ByVal StreamSize As Long, _
ByVal StreamBytesTransferred As Long, _
ByVal dwStreamNumber As Integer, _
ByVal dwCallbackReason As Integer, _
ByVal hSourceFile As Integer, _
ByVal hDestinationFile As Integer, _
ByVal lpData As Integer) As Integer
' Datei kopieren mit Fortschrittsanzeige
Public Function Fortschrittsanzeige( _
ByVal TotalFileSize As Long, _
ByVal TotalBytesTransferred As Long, _
ByVal StreamSize As Long, _
ByVal StreamBytesTransferred As Long, _
ByVal dwStreamNumber As Integer, _
ByVal dwCallbackReason As Integer, _
ByVal hSourceFile As Integer, _
ByVal hDestinationFile As Integer, _
ByVal lpData As Integer) As Integer
If Not pb1 Is Nothing Then
pb1.Value = 100 * TotalBytesTransferred / TotalFileSize
End If
Return 0
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
' Datei kopieren
Dim nResult As Integer = CopyFileEx("F:\Work Dev\VSNet" & _
"Dev\Test\nwind.mdb", "F:\Work Dev\VSNet Dev\Temp\nwind.mdb", _
AddressOf Fortschrittsanzeige, _
0, _
bCancel, _
COPY_FILE_RESTARTABLE)
If nResult = 0 Then
nResult = Marshal.GetLastWin32Error()
MsgBox("Sorry, didn't work:" + nResult.ToString())
End If
End Sub________
Alle Angaben ohne Gewähr. Keine Haftung für Vorschläge, Tipps oder sonstige Hilfe, falls es schiefgeht, nur Zeit verschwendet oder man sonst nicht zufrieden ist |