on 06-16-2009 3:11 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
.....
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
85 | |
10 | |
9 | |
8 | |
8 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.