|
-
Mar 20th, 2012, 10:38 AM
#1
Thread Starter
Member
Capturing Dialog Response during CopyFile
I have an application that primarily moves files from one location to another. I need to get the user's response when asked by Windows if they would like to overwrite or rename the new file because it already exists in the destination selected on the form. I basically need to receive a boolean value so i can update the transaction logs. The function follows:
Code:
This function handles copying files from one location to the destination specified on the form
Public Function copyToNewLoc(ByVal source As String, ByVal destination As String, ByVal bln As Boolean) As Boolean
Try
' Copies files, and shows the probress bar during the file move
My.Computer.FileSystem.CopyFile(source, destination, FileIO.UIOption.AllDialogs)
bln = FileIO.UIOption.AllDialogs
Catch ex1 As NullReferenceException
MessageBox.Show("A null reference error occured. Please enter both source and destination paths to the file(s).")
bln = False
Catch ex7 As ArgumentOutOfRangeException
MessageBox.Show("An error occured: " & ex7.ToString)
bln = False
Catch ex2 As AccessViolationException
MessageBox.Show("The application experienced an access violation error when attempting to copy the file.")
bln = False
Catch ex3 As DirectoryNotFoundException
MessageBox.Show("The directory was not found.")
bln = False
Catch ex4 As FileNotFoundException
MessageBox.Show("The file was not found.")
bln = False
Catch ex5 As IOException
MessageBox.Show("An error occured when attempting to copy: " & ex5.ToString)
bln = False
Catch ex6 As Exception
MessageBox.Show("An error occured: " & ex6.ToString)
bln = False
End Try
Return bln
End Function
All help is greatly appreciated. Thanks.
-
Mar 20th, 2012, 12:24 PM
#2
Re: Capturing Dialog Response during CopyFile
My.Computer.FileSystem.CopyFile is a sub and it is not return a value to tell what was the user response.
-
Mar 20th, 2012, 12:50 PM
#3
Re: Capturing Dialog Response during CopyFile
Even if that works as coded and I don't see any obvious errors, you still return nothing on your function. You need to return a boolean, eh?
EDIT:=
NEVER-EVER MIND!
HEy, I did not scroll the window of your code all the ewway down.
I goofed.
My bad.
UH, so what's your problem?
USe Streamwriter and set to ovewrwrite and forget your Windows UI..
-
Mar 20th, 2012, 01:13 PM
#4
Re: Capturing Dialog Response during CopyFile
 Originally Posted by proneal
Even if that works as coded and I don't see any obvious errors, you still return nothing on your function.
This line bln = FileIO.UIOption.AllDialogs will make the function return True when copying success, but there are two mistakes
1. bln = FileIO.UIOption.AllDialogs should replaced with bln = True
2. the parameter ByVal bln As Boolean has no meaning and must delete it.
-
Mar 20th, 2012, 01:17 PM
#5
Re: Capturing Dialog Response during CopyFile
 Originally Posted by 4x2y
This line bln = FileIO.UIOption.AllDialogs will make the function return True when copying success, but there are two mistakes
1. bln = FileIO.UIOption.AllDialogs should replaced with bln = True
2. the parameter ByVal bln As Boolean has no meaning and must delete it.
OH, okay, I see the light brother
-
Mar 20th, 2012, 03:50 PM
#6
Thread Starter
Member
Re: Capturing Dialog Response during CopyFile
Thanks for the advice. I actually reworked my code to exclude booleans and dialogs from appearing when running the copyfile function. I have all exceptions issueing a failure string message that is sent back to the calling function, which updates the listbox log.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|