Skip to Content
0
Former Member
Apr 16, 2012 at 02:58 PM

Error OpenFileDialog

358 Views

Hi Friends

I'm an addon DEVELOPING SAP 8.81, when generating an error generatedOpenFileDialog

El subproceso actual debe establecerse en el modo de subprocesamiento controlado simple (Single Thread Apartment, STA) para poder realizar llamadas OLE. Asegúrese de que la función Main tiene marcado STAThreadAttribute. Esta excepción sólo se desencadena

My code is as follows


Public Function abrirOpenFileDialog()

Try

Dim MyTest As New OpenFileDialog

Dim MyProcs As Process()

MyProcs = Process.GetProcessesByName("SAP Business One")

If MyProcs.Length > 0 Then

'For i As Integer = 0 To MyProcs.Length - 1

'Dim MyWindow As New WindowWrapper(MyProcs(i).MainWindowHandle)

Dim MyWindow As New WindowWrapper(MyProcs(0).MainWindowHandle)

MyTest.Filter = "Text Documents (*.txt)|*.txt"

If MyTest.ShowDialog(MyWindow) = DialogResult.OK Then

coForm.DataSources.UserDataSources.Item("txt_archiv").Value = MyTest.FileName

System.Windows.Forms.Application.ExitThread()

Else

System.Windows.Forms.Application.ExitThread()

End If

'Next

Else

oAplicacionSBO.SetStatusBarMessage("No SBO instances found.")

End If

Catch ex As Exception

oAplicacionSBO.MessageBox("Error al Abrir OpenFileDialog. " & ex.Message)

End Try

End Function

Help Me! 😔