Call OpenFileName API From C#

  • Thread starter Thread starter Tank
  • Start date Start date
Tank,

I am curious, is there a reason you are not using the OpenFileDialog or
SaveFileDialog classes?
 
The reason is :

I have the following code :

OpenFileDialog filedlg = new OpenFileDialog();

filedlg.InitialDirectory = directory.Text;

filedlg.Filter = "lvl files (*.lvl)|*.lvl" ;
filedlg.FileName = "*.lvl";
filedlg.ValidateNames = false;

if (filedlg.ShowDialog() == DialogResult.Cancel)
return;

string dirname = Path.GetDirectoryName(filedlg.FileName);

I set the property ValidateNames to false. I didn't select any file when
the dialog box pop-ups. When I click the "Open" button, the dialog box was
closed. The problem is filedlg.FileName doesn't not contain anything. I
expect it to have something like this c:\Test\*.lvl (with Win32
OpenFileDialog, it will). The protected member of OpenFileDialog namely
fileNames and FileNameInternal do have the value but as it is a protected
member, the value is inaccessible. ) With OpenFileName Win32 API, I am able
to get the value.

Nicholas Paldino said:
Tank,

I am curious, is there a reason you are not using the OpenFileDialog or
SaveFileDialog classes?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tank said:
How do I call OpenFileName Win32 API from C# ? Can someone show me a sample
code ?
 
Back
Top