I want to open FolderBrowserDialog,
I am getting error as
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."
Then I added
System.Threading.Thread.CurrentThread.SetApartmentState(System.Threading.ApartmentState.STA)
And I got error as "Failed to set the specified COM apartment state."
Here is code
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
' Description that displays above the dialog box control.
System.Threading.Thread.CurrentThread.SetApartmentState(System.Threading.ApartmentState.STA)
MyFolderBrowser.Description = "Select the Folder"
' Sets the root folder where the browsing starts from
MyFolderBrowser.RootFolder = Environment.SpecialFolder.MyComputer
Dim dlgResult As Windows.Forms.DialogResult = MyFolderBrowser.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
lblStatus.Text = MyFolderBrowser.SelectedPath
End If
End Sub
Please help.
Thanks!
Swapnil Raut