Solved

CFileDialog and Multiple File Types

Posted on 2008-06-17
7
1,044 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

626 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