Solved

CFileDialog and Multiple File Types

Posted on 2008-06-17
7
964 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find Visual Studio Tools 2 113
Infragistics Ultragrid 3 127
Configure a Local PHP Interpreter for Phpstorm 2 349
Exception thrown at 0x00007FFD5BC81F28 7 50
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

820 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