Calling a Windows API Function

S

Stewart Berman

I tried the OpenFileDialog class and I have a few questions:
1. How do you specify force show hidden files?
2. Why, when you can only select files from one folder is the path repeated with each file name in
FileNames[]? Shouldn't there be a Path property? Unmanaged code using the API only returns the
path once following by the list of file names.
3. If the user presses the Cancel button the class still returns one file with a zero length string
as the name. That is opf.FileNames.Count is 1 and opf.FileNames[0] is "". Shouldn't the
FileNames.Count be zero if no files were selected?
 
S

Stewart Berman

3. If the user presses the Cancel button the class still returns one file with a zero length string
as the name. That is opf.FileNames.Count is 1 and opf.FileNames[0] is "". Shouldn't the
FileNames.Count be zero if no files were selected?

A little research shows that it returns whatever was in the FileName property when the ShowDialog
method is called. Apparently, setting the FileName property sets the FileNames.Count to 1 and the
FileNames[0] to the contents of the FileName property. The only way to get back a zero count when
the user cancels is to set FileName = null before calling the ShowDialog method.

Stewart Berman said:
I tried the OpenFileDialog class and I have a few questions:
1. How do you specify force show hidden files?
2. Why, when you can only select files from one folder is the path repeated with each file name in
FileNames[]? Shouldn't there be a Path property? Unmanaged code using the API only returns the
path once following by the list of file names.
3. If the user presses the Cancel button the class still returns one file with a zero length string
as the name. That is opf.FileNames.Count is 1 and opf.FileNames[0] is "". Shouldn't the
FileNames.Count be zero if no files were selected?

[email protected] ("\"Ji Zhou [MSFT]\"") said:
Hello Stewart Berman,

As I have stated in my previous reply, in the .NET environment, we have
already provided the corresponding API, OpenFileDialog class which is more
powerful and easier to use than the comdlg32.dll's GetOpenFileName. Why not
use the OpenFileDialog class?

The codes are very simple to get multiple selected files,

OpenFileDialog opf = new OpenFileDialog();
opf.Multiselect = true;
if (opf.ShowDialog() == DialogResult.OK)
{
foreach (string name in opf.FileNames)
{
Debug.Print(name + "\r\n");
}
}

If you have any business reason for having to choose the comdlg32's native
API, please feel free let me know. Then we can have a future discussion on
this issue. Have a good day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top