CFileDialog saves file in Project File, not Specified File
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: CFileDialog saves file in Project File, not Specified File

  1. #1
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    CFileDialog saves file in Project File, not Specified File

    Hello,
    I'm very new to MFC & VisualC++. I'm using MSVS2010 Pro
    I am trying to write/debug a simple form that saves and restores the content of some edit controls. It seems to work as expected, except the file saves only to the Project Folder, regardless of where I browse and select to save the file. I wonder if I'm missing a parameter and someone could help me?
    (I hope this makes sense...)

    Code:
    void CMFC_FileDialogDlg::OnBnClickedbtnsave()
    {
    	this->UpdateData();
    	CFile f;
    
    //Kinda Correct, Works but still saves in Project Folder
    	BOOL b_OpenFileDialog = FALSE;	//this doesn't act as bool in CFileDialog?
    	LPCTSTR lpszDefExt = L"bcr";
    	LPCTSTR lpszFileName =  L"Car_Description";
    	DWORD dwFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
    	LPCTSTR lpszFilter =  L"BCR Files (*.bcr) |*.bcr|All Files (*.*)|*.*|";
    	LPCTSTR pParentWind = NULL;
    	int dwSize = 0;
    	int bVistaStyle = 1;
    	CFileDialog FileDlg( FALSE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, NULL, dwSize, bVistaStyle);
    
    
    	if( FileDlg.DoModal() == IDOK )
    	{
    		//CString m_strPathname = FileDlg.GetPathName();	//This actually gets intended folder name
    		
    		f.Open( FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
    			CArchive ar(&f, CArchive::store);	//This seems to be the save & restore cmd
    
    			ar << m_Make << m_Model << m_Year << m_Doors << m_Owner;	//These are the edit controls we're saving/restoring
    			ar.Close();
    }
    	else
    		return;
    	f.Close();
    }
    My only experience is a little simple VB programming in Excel, so any specific examples would be much appreciated!
    Also, rules seem to change from version to version? I have to "update" a number of undocumented programs. If anyone knows of any online tutorials I could read/follow along with that are somewhat up-to-date I would really appreciate it.
    Thank you!

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,987

    Re: CFileDialog saves file in Project File, not Specified File

    Code:
    		//CString m_strPathname = FileDlg.GetPathName();	//This actually gets intended folder name
    		
    		f.Open( FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
    You had it right in the line that's commented out.

  3. #3
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    Re: CFileDialog saves file in Project File, not Specified File

    Is that actually a command? Do I need to implement it somewhere?
    If I watch m_strPathname it's correct for where I intended it to save, but it still saves in the Project Folder.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,987

    Re: CFileDialog saves file in Project File, not Specified File

    I meant GetPathname vs GetFileName

  5. #5
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    Re: CFileDialog saves file in Project File, not Specified File

    Oh! That did it - thank you!
    Must have been a typo in the tutorial.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center