Click here to Skip to main content
15,921,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I close the FolderBrowserDialog when the cancel button is pressed?
Here is my code:
VB
Private Sub BackupButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupButton.Click
    With FolderBrowserDialog1
        .Description = "Select Backup Location:"
        .RootFolder = Environment.SpecialFolder.Desktop
        .SelectedPath = Environment.SpecialFolder.Desktop
        If .ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                destPath = .SelectedPath
            Catch ex As Exception
            End Try
        ElseIf (.ShowDialog = DialogResult.Cancel) Then
            Return
        End If
    End With
    sourcePath = Application.StartupPath & "\SavedFiles\"
    'If Not Directory.Exists(sourcePath) Then
    'MsgBox("Source folder does not exist")
    'Return
    'End If
    CopyDir.CopyAll(New DirectoryInfo(sourcePath), New DirectoryInfo(destPath + "\SavedFiles\"))
End Sub

In the above code, I do not know what command can close that dialog when the cancel button is pressed. Any tips?
Posted

1 solution

Never mind, fixed it myself after spending a lot of time debugging. All you had to do was move the CopyDir and sourcePath from the bottom in between the Try statement and delete the ElseIf and te Return after the End Try statement and it worked fine. The problem was it was either showing the dialog twice when the cancel button was pressed, or it was locking up. Either way it is now working. :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900