cancel
Showing results for 
Search instead for 
Did you mean: 

Open Dialogue Browse button problem

Former Member
0 Kudos

Hi i used the following code to get the open dialogue box on browse button pressed event. my requirement is similar to sales oppurtunity attachemnts. my code is working well in our machines we saved lot of attachemnts and viewed also.. but not possible to get the open dialogue box in client machines. browse button not responding anything.. any suggestion..

Private Sub OpenFile(ByRef BubbleEvent As Boolean)

Try

ShowFolderBrowserThread = New Threading.Thread(AddressOf ShowFolderBrowser)

If ShowFolderBrowserThread.ThreadState = ThreadState.Unstarted Then ShowFolderBrowserThread.SetApartmentState(ApartmentState.STA)

ShowFolderBrowserThread.Start()

ElseIf ShowFolderBrowserThread.ThreadState = ThreadState.Stopped Then

ShowFolderBrowserThread.Start()

ShowFolderBrowserThread.Join()

End If

Catch ex As Exception

sbo_application.MessageBox("OpenFile" & ex.Message)

End Try

Private Sub ShowFolderBrowser()

Dim MyTest As New OpenFileDialog

Dim MyProcs() As System.Diagnostics.Process

Dim filename As String

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

If MyProcs.Length = 1 Then

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

'// WindowWraper concepts are used to access open dialogue box of windows

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

MyTest.Filter = "Excel files (.xls)|.xls|Document files (.doc)|.doc|Presentation (.ppt)|.ppt|Adobe PDF Files (.pdf)|.pdf|Text Documents (.txt)|.txt" '|All Files (.)|."

'MyTest.InitialDirectory = "C:\Program Files\SAP\SAP Business One\Attachments"

'// Initial path for open dialogue box

'// We can change as per the requirements

MyTest.InitialDirectory = "C:\Program Files\SAP\SAP Business One\Attachments"

.

.

.

end sub

Public Class WindowWrapper

Implements System.Windows.Forms.IWin32Window

Private _hwnd As IntPtr

Public Sub New(ByVal handle As IntPtr)

_hwnd = handle

End Sub

Public ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle

Get

Return _hwnd

End Get

End Property

End Class

regards,

ganesh

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I´m having problems with this example I loose the thread and the add-on crash.

Former Member
0 Kudos

Hi,

Where you are getting error.. its working fine for me now..

please elaborate where you getting problem.

Regards,

Ganesh k

Former Member
0 Kudos

Hi,

I don´t know exactly how to explain this.The code works fine, the windows open , i select the path and then when i press the ok button the thread seems to loose, and the add on get freeze.

Former Member
0 Kudos

Hi,

how you handled the event of OK button in opendialogue box..

Ex,

.

.

.

.

MyTest.InitialDirectory = "C:\Program Files\SAP\SAP Business One\Attachments"

After this,

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

filename = MyTest.FileName

Dim f As New System.IO.FileInfo(filename)

'

'

Your requirements

'

'

'

End if

Regards,

Ganesh k

Use Try catch blocks and find what error you are getting..

Edited by: Ganesh Karunakaran on Nov 10, 2008 6:37 PM

Former Member
0 Kudos

Hi...

Search forum itself u get more Ideas.

Reagrds..

Billa 2007