HOWTO set FileDialog to open a specific directory?

Hello!

I have a SDI Document/View MFC app and I would like that the Open  FileDialog and Save/Save as... FileDialog open on a default directory.

Thanks a lot!
jussaraAsked:
Who is Participating?
 
Chandra VConnect With a Mentor ConsultantCommented:
Assuming

CFileDialog myDlg;//Use your own

Use

myDlg.m_ofn.lpstrInitialDir="c:\\";// Use your Own

to set your initial directory.
0
 
migelCommented:
Hi!
try this:

add command handler for ID_FILE_OPEN  to the your APP class:

void CMyApp::OnFileOpen()
{
     // TODO: Add your command handler code here
     CString newName = _T("C:"\*.*");
     if (!DoPromptFileName(newName, AFX_IDS_OPENFILE,
          OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, NULL))
          return; // open cancelled
     
     OpenDocumentFile(newName);
}

0
 
migelCommented:
of course use your path instead
C:\*.*
0
 
leowlfCommented:
Or

_chdir( "c:\\" );
CFileDialog myDlg(1);
myDlg.DoModal();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.