We help IT Professionals succeed at work.

CFileDialog Question...

jhattingh
jhattingh asked
on
Medium Priority
364 Views
Last Modified: 2013-11-20
When I use CFileDialog, giving users the ability to sort by file type through the use of the drop-down list, how do I know what they "chose"?

You see, I'm finding that people often don't put a file extension because they believe (understandably) that the context will dictate the file extension, and it's causing me a small headache.

Comment
Watch Question

CERTIFIED EXPERT

Commented:
try

CString CFileDialog::GetFileExt();

Author

Commented:
This is what I am currently doing:

strOutputPath     = dlg.GetPathName();
strExt          = dlg.GetFileExt();
strTitle     = dlg.GetFileTitle();

if (strExt.IsEmpty())
{
   AfxMessageBox("Please browse again and specify a file extension for your output file");
   return false;
}


strExt *does* come up empty...


Thanks for the response...
Commented:
The CFileDialog class has a overridable function OnTypeChange that is called when the user changes the type form the combo. U can use that to determine the current file type.

Also u can provide a defalut extension as a param to the constructor of the CFileDialog class that is appended to all filenames without an extension chosed by the user.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.