Solved

CFileDialog

Posted on 2003-12-01
4
455 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
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now