GetFolderPath() gives Assertion error even with OFN_EXPLORER style!
Hello Everybody!!
I found no reason for having "Debug Assertion Error" on calling GetFolderPath(). I have already mentioned OFN_EXPLORER style.
void CMyDlg::OnBnClickedOpen()
{
CFileDialog MyOpenCmd(TRUE,NULL,NULL,OFN_EXPLORER,"All Files (*.*)|*.*||");
INT_PTR check = MyOpenCmd.DoModal();
if(check==IDOK)
CString DesiredDIR = MyOpenCmd.GetFolderPath();
}
What is wrong with above code??
# 1 Re: GetFolderPath() gives Assertion error even with OFN_EXPLORER style!
You can call this method only while the dialog box is being displayed. After the dialog box has been closed, this function will no longer work, and the method will fail with an assertion.
After pressing OK button the dialog is not in display mode that is why you getting assert. If you want to get the path you can use GetPathName().
Cheers
# 2 Re: GetFolderPath() gives Assertion error even with OFN_EXPLORER style!
After pressing OK button the dialog is not in display mode that is why you getting assert. If you want to get the path you can use GetPathName().
Cheers
Its amazing!!
GetPathName() is working well...
My requirement is to get the directory only not File that I had selected thru Open CommonDialog. So, is there some way to get directory path..
Cheers too
# 3 Re: GetFolderPath() gives Assertion error even with OFN_EXPLORER style!
Its amazing!!
GetPathName() is working well...
My requirement is to get the directory only not File that I had selected thru Open CommonDialog. So, is there some way to get directory path..
Cheers too
If you want only browsing to folder and you dont interested in the file name you should be using ::SHBrowseForFolder() (http://msdn2.microsoft.com/en-us/library/ms647664.aspx).
Another option is to call ::PathRemoveFileSpec() (http://msdn2.microsoft.com/en-us/library/ms628619.aspx) on the return value of GetPathName().
Cheers