Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFileDialog::GetFolderPath

Status
Not open for further replies.

mzufferey

Programmer
Aug 30, 2001
4
CH
Hi all,

I have a little problem with GetFolderPath.

First, I create an object f as this:

CFileDialog f(true, "txt", NULL, OFN_EXPLORER, "Texte Files (*.txt)|*.txt|", this);

Then, I want to retrive to open folder path of a file, but if I do this:

m_list.AddString((const char*) (LPCSTR) f.GetFolderPath());

I have an assertion problem.

So, how can I do, to obtaining the open folder path of a file.

Many thanks,

Michael.




 
In my opinion the file name contains its full path. I don;t know in MFC, but for WinAPI it is true. Ion Filipski
1c.bmp


filipski@excite.com
 
Try using GetPathName() instead of GetFolderPath()
Here is an example....

CString strFilter = "Bitmap Files (*.bmp)|*.bmp|Jpeg Files(*.jpg)|*.jpg||";

CFileDialog fDlg (TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,strFilter);

if (fDlg.DoModal() == IDOK)
{
CString m_filepath = _T("");
m_filepath.Format("%s",fDlg.GetPathName());

}

//now you have the full path

m_list.AddString(m_filepath);




 
why do you have to cast the result to (const char *)???
I think you should drop the conversion...
[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
(const char*) (LPCSTR) ????
Double conversion to the same thing ???
(Because LPCSTR is defined as const char* )
Anyway I don't think you need a conversion at all.

GetFileName is the member function of file dialog for what you need.
GetFolderPath does not seem to be a member of CFileDialog.

HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top