cancel
Showing results for 
Search instead for 
Did you mean: 

OpenFileDialog for B1

costas_ioannou2
Active Participant
0 Kudos

Hi, I noticed that the sdk doesn't seem to have an OpenFileDialog, where you can browse for a file. I tried using the one that comes with dotnet together with the UI API, however it doesn't seem to appear. Can anyone help with this? Thanks

Here is my code:

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = @"C:\";

openFileDialog1.Title = "Select a File";

openFileDialog1.Filter = "Access Files|*.mdb";

if (openFileDialog1.ShowDialog() != DialogResult.Cancel)

{

oEdit.Value = openFileDialog1.FileName;

}

else

{

oEdit.Value = "";

}

string loadString = oEdit.Value.ToString();

Edited by: Costas Ioannou on Jun 16, 2009 4:11 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

And



Public Sub ShowFolderBrowser()

        Dim f As New FileIOPermission(PermissionState.None)
        f.AllLocalFiles = FileIOPermissionAccess.AllAccess
        Dim MyProcs() As System.Diagnostics.Process
        BankFileName = ""
        Dim OpenFile As New OpenFileDialog

        Try
            OpenFile.Multiselect = False
            OpenFile.Filter = "|*.*"
            Dim filterindex As Integer = 0
            Try
                filterindex = 0
            Catch ex As Exception
            End Try

            OpenFile.FilterIndex = filterindex

            OpenFile.RestoreDirectory = True
            MyProcs = Process.GetProcessesByName("SAP Business One")

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

                    Dim MyWindow As New WindowWrapper(MyProcs(i).MainWindowHandle)
                    Dim ret As DialogResult = OpenFile.ShowDialog(MyWindow)

                    If ret = DialogResult.OK Then
                        Dim FileName As String = OpenFile.FileName
                        OpenFile.Dispose()
                    Else
                        System.Windows.Forms.Application.ExitThread()
                    End If
                Next
            End If
        Catch ex As Exception
            m_SBO_Application.StatusBar.SetText(ex.Message)
            BankFileName = ""
        Finally
            OpenFile.Dispose()
        End Try

    End Sub

costas_ioannou2
Active Participant
0 Kudos

Hey thanks for replying.

I'll need to try and see how this will work in c#. If anyone has a c# exapmle it would save me translating.

Former Member
0 Kudos

HI,

IN C# and VB.NET donwload from

[http://www.progi-tech.hu/ShowFileOpenDialog.zip]

Regards

J:

costas_ioannou2
Active Participant
0 Kudos

Hey thanks

That was a great help.

Former Member
0 Kudos

Janos Nagy, I got it. Thank you very much.

Answers (2)

Answers (2)

0 Kudos

try this,

System.Windows.Forms.Formform=newSystem.Windows.Forms.Form();
form.TopMost = true;
OpenFileDialog objOpenFileDialog =new OpenFileDialog();
objOpenFileDialog.InitialDirectory =System.Windows.Forms.Application.StartupPath +"\";
objOpenFileDialog.Filter="Excel files (*.xls)|*.xls";
if(objOpenFileDialog.ShowDialog(form)!= DialogResult.Cancel)
{
string ExcelFilePath = objOpenFileDialog.FileName;
.....
}
Former Member
0 Kudos

HI,

if you search the forum, you will see a lot of solution for openfiledialog. Here is an example but in VB.NET,

call findfile to get the filename


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



Public Function FindFile() As String

        Dim ShowFolderBrowserThread As Threading.Thread
        Try
            ShowFolderBrowserThread = New Threading.Thread(AddressOf ShowFolderBrowser)
            If ShowFolderBrowserThread.ThreadState = System.Threading.ThreadState.Unstarted Then
                ShowFolderBrowserThread.SetApartmentState(System.Threading.ApartmentState.STA)
                ShowFolderBrowserThread.Start()
            ElseIf ShowFolderBrowserThread.ThreadState = System.Threading.ThreadState.Stopped Then
                ShowFolderBrowserThread.Start()
                ShowFolderBrowserThread.Join()

            End If
            While ShowFolderBrowserThread.ThreadState = Threading.ThreadState.Running
                Application.DoEvents()
            End While
            If BankFileName <> "" Then
                Return BankFileName
            End If
        Catch ex As Exception
            m_SBO_Application.MessageBox("FileFile" & ex.Message)
        End Try

        Return ""

    End Function

Continued in next reply..

Regards,

J.

Edited by: Janos Nagy on Jun 16, 2009 6:18 PM

Former Member
0 Kudos

Hi Janos Nagy

With all due respect, I tried to implement your code but your code isn't working for me.

Can you elaborate more ? I'm using VB2005.

Problem is I can't implement IWin32Window interface, even the sample code from MSDN doesn't work.

Currently I'm using common dialog 6 control for old/existing addons. If I can implement this method, I can deploy my addon installers with lesser dll files.

Thanks in advance.

Kalvin

Former Member
0 Kudos

Wee my prevoius answer

costas_ioannou2
Active Participant
0 Kudos

Hey I managed to get the add-on to work but something strange happens. When I run the add-on on Windows Vista the openFiledialog appears. When I run it on Windows Server 2003 nothing appears. Any idea why?

Former Member
0 Kudos

HI,

IN Windows 2003 server more than 1 SAP B1 application is running in the same time, that's the reason why it is not appearing?

or You are not superuser. /Power user at least

Please check.

Regards,

J.

costas_ioannou2
Active Participant
0 Kudos

Hmm I seem to be wrong about something. The version running on Windows server 2003 is SAP 2007. The add-on works on Windows server 2003 if I use SAP 2005, but not when I use SAP 2007. Has anyone else seen this?

Edited by: Costas Ioannou on Jun 22, 2009 11:25 AM