Share via

CFileDialog Class GetFileName() function returns NULL, when try to get file name using ftp server path.

Raghav Kuppili 1 Reputation point
2021-06-14T10:12:27.927+00:00

While browsing the local file from our system the file name is coming but when we are trying to browse it from FTP server path for e.g.,
FTP://xxx.xxx.xxx.xxx/ unable to get the file name in VC++.

This is the code i am trying to get FTP file.

CFileDialog dlg(TRUE, NULL, NULL, OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES,
_T("All Files|.||"), this);

if (dlg.DoModal() == IDOK)
{
    m_bEditingFilename = true;
    m_strLocalFile = dlg.GetPathName();
    m_strFileName = dlg.GetFileName();      
    UpdateData(FALSE);
}
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


1 answer

Sort by: Most helpful
  1. Guido Franzke 2,191 Reputation points
    2021-06-15T05:52:42.19+00:00

    Hello,
    as far as I know CFileDialog does not download files from web servers.
    Maybe this code does:

    TCHAR lFilter[] = _T("All Files (*.*)\0*.*\0");  
    TCHAR lFile[0x10000] = _T("");  
    
    OPENFILENAME lOFN;  
    
    memset(&lOFN, 0, sizeof(lOFN));  
    
    lOFN.lStructSize = sizeof(lOFN);  
    lOFN.hwndOwner = this->GetSafeHwnd();  
    lOFN.lpstrFilter = lFilter;  
    lOFN.lpstrFile = lFile;  
    lOFN.nMaxFile = sizeof(lFile) / sizeof(lFile[0]);  
    lOFN.Flags = OFN_EXPLORER | OFN_ENABLESIZING;  
    
    if (::GetOpenFileName(&lOFN) == TRUE) {  
        AfxMessageBox(lFile);  
    } 
    

    Regards, Guido

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.