1

I would like to open a file dialog and allow user to select only the file with name "myapplication.ini" and user can only browse folder's to check if the file is existing to select it.

so i came across CFileDialog which would do almost what i want other than limiting it to display only files with name "myapplication.ini"

currently my usage of CFiledialog

CFileDialog FileDialog(TRUE,"features.ini", NULL,OFN_HIDEREADONLY,NULL);

I am not sure what could should be changed to make it work as i expected.

2 Answers 2

3

That sounds like a poor UI. Even if you filter out all but that file, the user can override the filter. If you aren't going to allow the user to make a choice of file name, why ask them for their choice?

What you are actually doing, in my view, is asking the user to select a folder. So instead of the file dialog, show them a folder selection dialog, CFolderPickerDialog.

Sign up to request clarification or add additional context in comments.

4 Comments

End user has to select the file from his location and my application will accept only with the specific filename.So i had to restrict it.
I understand fully. So ask the user to select the location rather than the file. Use a folder selection dialog and not a file selection dialog.
Yes, this would be my preferred solution too, @David is absolutely correct, a file dialog is the wrong way to go. +1.
But from a user perspective it would be nice to know if the specific file is in said folder.
3

Declare the filter string like this:

static TCHAR BASED_CODE szFilter[] = _T("features.ini (features.ini)|features.ini|"); 

and then pass it to your CFileDialog ctor:

CFileDialog FileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter); 

4 Comments

it worked after i chnage the szFilter argument to the correct argument,edited your answer.Thanks
The user types * into the filename edit box, presses enter, and all the files are revealed.
You can solve that by deriving from CFileDialog, overriding OnInitDone method with the following code: CWnd* dlgitm = GetParent()->GetDlgItem(edt1); dlgitm->EnableWindow(FALSE); This will disable the editing of the textbox text. cheers mate
You could do that, but won't it confuse the user? I know I'd be perplexed to be offered a file dialog with an edit box, but then find that the edit box was disabled.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.