-1

I have a windows form that contains a SaveFileDialog as a component. This form is called from a library (.dll). When you click on btnExport you should see the save file dialog window.

My problem is that SaveFileDialog1.ShowDialog doesn't show any window to select the directory path.

This is my code:

Private Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click
    SaveFileDialog1.Filter = "XLS File|*.xls"
    SaveFileDialog1.Title = "SaveFileDialog title"
    Try
       ' this should open the dialog
       If Me.SaveFileDialog1.ShowDialog() = DialogResult.OK Then
          ' Do something
       Else
          ' This is a custom function to show messages
          ShowCustomMessage("Error opening SaveFileDialog")
       End If
    Catch ex As Exception
       ' Show exception
    End Try
End Sub
  • What kind of application are you running? i.e. console vs. winforms? Do you have the proper references to System.Windows.Forms? I could see it not working if you have created a new UI thread to host your form which was not explicitly marked STA. Show more code including how the form is shown and its host thread if applicable. – djv Nov 06 '17 at 19:45
  • If you are creating your own thread to host the referenced dll's form, see [this post](https://stackoverflow.com/a/127340/832052). (Still awaiting more code from you). – djv Nov 06 '17 at 19:49

1 Answers1

0

Your code works. You could try the following -

  1. Try removing the Try-Catch-End Try as it could be hiding an error from you since you didn't implement anything to handle the Catch.

  2. Try specifying the Owner object when calling ShowDialog() to ensure it is not going behind your main form.

    Me.SaveFileDialog1.ShowDialog(Me) ...

GMan80013
  • 536
  • 4
  • 13