Solved

CFileDialog

Posted on 2003-12-01
4
481 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans

691 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