Solved

CFileDialog and Multiple File Types

Posted on 2008-06-17
7
930 Views
Last Modified: 2013-12-14
In my VC 6.0 app, I display a CFileDialog.  I simply want it to display all files with the following extensions, AT THE SAME TIME: ".txt", and ".xls".  I can get CFileDialog to display just the text files, or just the spreadsheet files, but I can't get it display both types at the same time.

Thanks, ahead of time.
0
Comment
Question by:clintonJ
7 Comments
 
LVL 19

Expert Comment

by:alb66
ID: 21802469
You must use the following filter:

Text file (*.txt)|*.txt|Excel file (*.xls)|*.xls||
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 250 total points
ID: 21802477
Hi ClintonJ,

you just can seperate multiple extensions with a ;

I.e. use this filter string:

"Excel Files (*.txt;*.xls)|*.txt;*.xls|All files (*.*)|*.*||";


Hope that helps,

ZOPPO
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21802482
When you create it you can set the filter to be multiple types, using | as a separator, something like...

CFileDialog OpenDlg(false,NULL,NULL,0,_T("TXT Files (*.txt)|*.txt|XLS Files (*.xls)|*.xls"),NULL);
http://msdn.microsoft.com/en-us/library/wh5hz49d(VS.80).aspx

lpszFilter
A series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files will appear in the Files list box. See the Remarks section for more information on how to work with file filters
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Expert Comment

by:alb66
ID: 21802507
ZOPPO is right; I misunderstud the question.
0
 

Author Comment

by:clintonJ
ID: 21802571
OK, we're getting there.  The constructor for CFileDialog looks like this:

CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );

So, thanks to you, :) my lpszFilter parameter now looks like this:

 lpszFilter = "Data Files (*.txt;*.xls)|*.txt;*.xls|All files (*.*)|*.*||";

When the CFileDialog displays, the "Files of Type" textbox now displays the correct file extensions (.txt AND .xls).  

One small problem though: The only file names  that display are .txt files, even though I also have .xls files in the same folder.  Do I need to also adjust LPCTSTR lpszDefExt to get the excel file names to also display?

0
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 250 total points
ID: 21802617
This works properli with VS2003:

      CFileDialog dlg( true, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
                                      "Data Files (*.txt;*.xls)|*.txt;*.xls|All files (*.*)|*.*||",
                                      NULL );
      dlg.DoModal();
0
 

Author Closing Comment

by:clintonJ
ID: 31467937
Thanks very much.  Perfecto!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
installing and using WTP plugin eclipse MARS 3 97
C++ to C# code conversion issue 4 98
Header of docx file 17 97
How to measure sizes and angles in scanned images ? 3 51
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now