473,473 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Opening multiple files in an MFC dialog application

79 New Member
I want to be able to select mutliple files from a standard File Open dialog box, and be able to open all those files simultaneously.

How can this be done? Is there a specific flag that you can use in the CFileDialog class constructor?

This is how I've been doing it, but just for one file:

CFileDialog FileDlg(TRUE, _T("*.txt"), NULL, 0, _T("Text Files (*.txt)|*.txt|" ));

Thanks
Jul 10 '07 #1
3 4425
weaknessforcats
9,208 Recognized Expert Moderator Expert
Read this. Especially, how to use OFN_ALLOWMULTISELECT.
Jul 11 '07 #2
ahammad
79 New Member
Thanks, I finally got it to work, but now there is another problem.

If I select a small number of files, it works. If I select a larger number of files (+5), it exits the loop as if I had clicked "cancel" in the dialog box.

Expand|Select|Wrap|Line Numbers
  1. CFileDialog cfileDlg( TRUE, _T("*.cpf"), NULL, OFN_ALLOWMULTISELECT, _T("CPF Files (*.cpf)|*.cpf|" ));
  2.  
  3.     CString csFileDlgTitle;
  4.  
  5.     cfileDlg.m_ofn.lpstrTitle = csFileDlgTitle;
  6.  
  7.     //int nRet = cfileDlg.DoModal( );
  8.     //ASSERT( ( nRet != IDOK ) || ( nRet != IDCANCEL ) );
  9.  
  10.     if (cfileDlg.DoModal() != IDOK) {
  11.         return;    //EXITS HERE IF I SELECT A LOT OF FILES, REGARDLESS OF WHAT I CLICK//
  12.     }
  13.  
  14.     POSITION pos ( cfileDlg.GetStartPosition() );
  15.  
  16.     while( pos )
  17.     {
  18.         CString csFileName(  cfileDlg.GetNextPathName( pos ) );
  19.  
  20.         FileOpenInput(csFileName);
The code that was commented out worked before, I took it out for other reasons.

I marked where the function terminates. That if statement is meant to be entered if the user clicks cancel in the File Open dialog box. What is the reason for this?

Thanks
Jul 11 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
So if DoModal() does not return IDOK, then what does it return??

I would have expected code like:
Expand|Select|Wrap|Line Numbers
  1. if (cfileDlg.DoModal() == IDCANCEL)
  2. {
  3.         switch(CommDlgExtendedError())
  4.         {
  5.               case: CDERR_FINDRESFAILURE
  6.                        // etc...
  7.                       break;
  8. //etc...
  9. }
  10. //Then you get here on IDOK
  11.  
Jul 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: yanivoliver | last post by:
Hey, I'm currently trying to find a way to open a dialog box that will allow me to select more than one file at a time, so if I want to upload select all the files in a directory, I won't have...
2
by: Johann Blake | last post by:
I can hardly believe I'm the first one to report this, but having gone through the newsgroup, it appears that way. I would like to open a solution in the VS.NET IDE that consists of multiple...
0
by: vinX | last post by:
Ok, i am making a file renaming utility, you can add filesize (in MB o KB), filepath, creation date and/or time, a counter, parent folder, th original name etc... I put the program in the...
2
by: Matt Hamilton | last post by:
I have an application page with a datagrid with a checkbox on each row. The user should check the rows they want to modify and then click a button. When the button is clicked, I have a Click...
5
by: Stanav | last post by:
Hello all, Thanks in advance for any replies... Now, my question is: Is it possible to do a multiple files download for a single response event on an aspx page? If there is, please give me some...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
4
by: Pieter | last post by:
Hi, From my VB.NET 2005 application I need to be able to open Files an Directory's with their default application: - A word-doc must open in word - A excell-document in Excel etc - in case...
10
by: kimiraikkonen | last post by:
Hi, I have an app which has a listbox and when i double click an associated fileS, i want their paths to be added into listbox in my application. This code works good when i try to open a...
1
navanova
by: navanova | last post by:
Greetings, I have a problem of opening ms word and excel files on my computer. The files are there for a long time. I use to open and modify them. Suddenly, when i try to open the word files, a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.