[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

CFileDialog

Posted on 2003-12-01
4
Medium Priority
?
492 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 250 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project

650 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