Solved

CFileDialog

Posted on 2003-12-01
4
469 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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…

840 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