Results 1 to 6 of 6

Thread: Capturing Dialog Response during CopyFile

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    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.

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    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.



  3. #3
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    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?

    vb Code:
    1. Return bin

    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..

  4. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Capturing Dialog Response during CopyFile

    Quote Originally Posted by proneal View Post
    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.



  5. #5
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Capturing Dialog Response during CopyFile

    Quote Originally Posted by 4x2y View Post
    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

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    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
  •  



Click Here to Expand Forum to Full Width