cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Open file dialog by clicking button?

Former Member
0 Kudos

Hi friends,

I have desigend a form which contains a button.If click that button , i want to get the <b>Open file dialog box (Windows form )</b> .

If i select the file I want to get the path of that file in editBox.

Expecting ur reply soon.

Thanks

SARAN

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi, Saran

You have to try this code,

First Add the Window Wrapper Class:

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

and call this function as Item_Click Event

Private Sub fillopen()

Dim mythr As New System.Threading.Thread(AddressOf ShowFileDialog)

mythr.SetApartmentState(Threading.ApartmentState.STA)

mythr.Start()

mythr.Join()

End Sub

Private Sub ShowFileDialog()

Dim oDialogBox As New OpenFileDialog

Dim strFileName, strMdbFilePath As String

Dim oEdit As SAPbouiCOM.EditText

Dim oProcesses() As Process

Try

'Form.Freeze(True)

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

If oProcesses.Length <> 0 Then

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

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

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

strMdbFilePath = oDialogBox.FileName

strSelectedFilepath = oDialogBox.FileName

Else

End If

Next

End If

Catch ex As Exception

objAddon.objApplication.MessageBox(ex.Message)

Finally

End Try

End Sub

Its Working

Former Member
0 Kudos

Dear All,

You may download a source code in VB and C# from the following link:

It was created by 2004 version several years before, but it is still working, and supports Terminal servers mode also.

Download link

Regadrs

János

Former Member
0 Kudos

Hi Saran,

can you let me know if you have got any solution to the file open problem you had..??

Thank you,

Srikanth

Former Member
0 Kudos

See this topic:

Gianluigi
Product and Topic Expert
Product and Topic Expert
0 Kudos

- you catch the button event

- in the event handler you open the open file dialog box

- you return the control to B1

if you need to get the file path you read it from the

edit box

Former Member
0 Kudos

Hi Gianluigi Bagnoli ,

I catched that event.But i do not know how to open the file dialog box and how to get that path of selected file into editBox.

I have desigend the form using vb.net.

We need code example.

Thanks for ur reply.Please reply for this too.

Thanks

SARAN

Former Member
0 Kudos

hi SRJJ.

You need to do this.

include a reference in your VB.NET Project

System.Windows.Forms

then

Dim loOFD As System.Windows.Forms.OpenFileDialog

Dim loEditText as SAPbouiCOM.EditText

loOFD = New System.Windows.Forms.OpenFileDialog

loOFD.ShowDialog()

loEditText = SBOApplication.Forms.Item(FormUID)

loEditText.String = loOFD.FileName

loEditText.Update

It´s All

Bye i will suppose that you give me some points jejejejej

=...(

bye

Former Member
0 Kudos

hi Elias Lora Guerra ,

Thanks for your reply.

i tryed with your code.

now i am getting the file path in text box---but <b><u>when i click the button the open file dialog box will display at desktop ,not in the SBO form.</u></b>if i select file then it shows in text box.

now i will save that record.if next time i will open the same record and <b>click on the path of file(in textbox)it directly opens the file</b> Like (humanresources>employee master data>attachments tab--->browse button

if u open any old record and click on the file path on path column it directly.

EXPECTING YOUR REPLY SOON

Thanks

SARAN

Former Member
0 Kudos

This Topic have a lot of code that could be helpfull for you and i dont answer the second point please you could be more explicit i don´t understand what you want to do.

Thks and i wait for my points please give me my first points.

See you

Elias