Showing results for 
Search instead for 
Did you mean: 

SaveFile dialogue

Former Member
0 Kudos

Hi collegues !

Could you point me please, how i can show Save File Dialogue window, so i could prompt my users to choose file where they would like to save data

Best regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi I want to know the files to be imported for commondialog

Answers (3)

Answers (3)

Former Member
0 Kudos

Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
Select Case pVal.ItemUID
Case "Btnbrowse" 
end select 
Private Sub *OpenFile*(ByRef BubbleEvent As Boolean)
ShowFolderBrowserThread = New Threading.Thread(AddressOf ShowFolderBrowser)
If ShowFolderBrowserThread.ThreadState = ThreadState.Unstarted Then ShowFolderBrowserThread.SetApartmentState(ApartmentState.STA)
ElseIf ShowFolderBrowserThread.ThreadState = ThreadState.Stopped Then
End If
Catch ex As Exception
sbo_application.MessageBox("SaveFile" & ex.Message)
End Try

Private Sub ShowFolderBrowser()
Dim MyTest As New SaveFileDialog
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"

If MyTest.ShowDialog(MyWindow) = DialogResult.OK Then
filename = MyTest.FileName
.your validations........

End If
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
Return _hwnd
End Get
End Property

End Class

To open the file you can use the follwing code on display button pressed.

Private Sub *fileopen*(ByVal filename As String)
'// Opening specified document with reference to the filename distributed 
Catch ex As Exception
sbo_application.StatusBar.SetText("File Not Found in Specified Path:" & filename, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
End Try
End Sub


Public Sub SBO_ManageItemEvent( _
  ByVal FormUID As String, _
  ByRef pVal As SAPbouiCOM.ItemEvent, _
  ByRef BubbleEvent As Boolean _
) ' Item Event Handler
  Dim oForm As SAPbouiCOM.Form
  oForm = SBO_Application.Forms.Item(FormUID)
  Select Case pVal.EventType
      Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
	  Select Case pVal.ItemUID
	      Case "btnBrowse"       ' Select file
		  If Not pVal.BeforeAction Then
		      Call ShowFolderBrowser(oForm)
		  End If
	  End Select
  End Select
  oForm = Nothing
End Sub
Private Sub ShowFolderBrowser(ByRef oForm As SAPbouiCOM.Form)
      ' ++++++++++++++++++++++++++++++++++++++++++++++++++
      ' I'm using default path...
      ' ++++++++++++++++++++++++++++++++++++++++++++++++++
      Dim sPath As String = SBO_Company.ExcelDocsPath
      SBO_Application.Desktop.State = BoFormStateEnum.fs_Minimized
      ' ++++++++++++++++++++++++++++++++++++++++++++++++++
      ' All windows down with command ^M
      ' ++++++++++++++++++++++++++++++++++++++++++++++++++
      Const KEYEVENTF_KEYUP = &H2
      Const VK_LWIN = &H5B
      Call keybd_event(VK_LWIN, 0, 0, 0)
      Call keybd_event(77, 0, 0, 0)
      Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
      Dim fileName As String = ""
      Dim OpenFileDialog As New OpenFileDialog
      OpenFileDialog.Title = "Select Excel File"
      OpenFileDialog.Filter = "Excel files (*.xls)|*.xls"
      If Not sPath.Equals("") Then
	  OpenFileDialog.InitialDirectory = sPath
	  OpenFileDialog.InitialDirectory = Me.SBO_FormEventHDL.BdgPathLog  '"C:\"
      End If
      If OpenFileDialog.ShowDialog() = DialogResult.OK Then
	  fileName = OpenFileDialog.FileName
	  sFileXls = fileName
	  ' ++++++++++++++++++++++++++++++++++++++++++++++++++
	  ' Here I post getted path into my edittext field
	  ' ++++++++++++++++++++++++++++++++++++++++++++++++++
	  Dim oEdit As SAPbouiCOM.EditText
	  Dim oItem As SAPbouiCOM.Item
	  oItem = oForm.Items.Item("eFileName")
	  oEdit = oItem.Specific
	  oEdit.Value = sFileXls
	  oItem = Nothing
	  oEdit = Nothing
      End If
  Catch ex As Exception
    ' log exception
      SBO_Application.Desktop.State = BoFormStateEnum.fs_Restore
      System.GC.Collect() 'Release the handle to the table 
  End Try
End Sub
Former Member
0 Kudos


You can use ActiveX control do this stuff.

first use this code while you load your page

'Add One Active-X Button for Browse
                oItem = oForm.Items.Add("BrowseA", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X)
                oItem.Top = 20
                oItem.Left = 20
                oItem.Width = 0
                oItem.Height = 0
                oActiveX = oItem.Specific
                oActiveX.ClassID = "MSComDlg.CommonDialog"
                oActiveX.ClassID = "{F9043C85-F6F2-101A-A3C9-08002B2F49FB}"

After this write this while pressing button

oOpenDialog = New OpenFileDialog()
                oForm = SBOApp.Forms.Item("frmHazard")
                oForm.Items.Item("BrowseA").Specific.Object.FileName = ""
                oForm.Items.Item("BrowseA").Specific.Object.Filter = "JPG(*.JPG,*.JPEG)|*.JPG;*.JPEG|GIF(*.GIF)|*.GIF|Bitmap (*.bmp)|*.bmp"

This will helps you

Former Member
0 Kudos


Take a look at the following post.

Hope it helps,

Vasu Natari.