Solved

CFileDialog

Posted on 2003-12-01
4
472 Views
Last Modified: 2008-02-26
I am using the following code to save a file . But Open statement is failing because of the \ character in the filename path. How to solve this. If hard code the filename like "c:\\abc.txt" it is working


CFileDialog fileDlg( FALSE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY, "All Files (*.csv)|*.csv||", this);
      fileDlg.m_ofn.lpstrTitle = "Select the File";
      if ( fileDlg.DoModal() == IDOK)
      {
             CString m_txtFileName = fileDlg.GetPathName();
             CStdioFile m_logFile;            
             CFileException fileException;
      
if( !m_logFile.Open( m_txtFileName, CFile::modeCreate | File::modeWrite|CFile::shareExclusive , &fileException ) )
            {
                  #ifdef _DEBUG
                  afxDump << "File could not be opened " << fileException.m_cause << "\n";
                  #endif
                  return;
            }


            if( !m_logFile.Open( m_txtFileName, CFile::modeCreate | CFile::modeWrite|CFile::shareExclusive , &fileException ) )
            {
                        #ifdef _DEBUG
                  afxDump << "File could not be opened " << fileException.m_cause << "\n";
                  #endif
                  return 0;
      }
0
Comment
Question by:Gopakumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9850304
Remove OFN_ALLOWMULTISELECT flag. What is the value of m_txtFileName in debugger?
 
0
 

Expert Comment

by:kallzz
ID: 9857411
I dont think so the open will fail when u provide the m_txtFileName in the Open function.
Please see the file attributes
0
 
LVL 1

Accepted Solution

by:
SubodhKatiyar earned 125 total points
ID: 9857681
hi there

i created a little function for you try this

CString fixsplchar(CString mystring)
{
      CString tmpstring;
      int i;
      for(i=0;i< (int)mystring.GetLength();i++)
      {
            tmpstring+=mystring.GetAt(i);
            if(mystring.GetAt(i)==92)
                  tmpstring+=mystring.GetAt(i);
      }
      return tmpstring;
}

//this will take care of single backspace truncation in special
//processing and will provide a way for overriding the handling of
// escape char, pass the string directly from fileopendialog to this
// function and the returning string pass on to fileopen function.

//good luck buddy
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question