Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CStdioFile problem

CStdioFile problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studio
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lisoft
    wrote on last edited by
    #1

    Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample: CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); } I'm sure the absolute file path/name is correct and have read/write permission to the file location. When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.

    Lisoft

    N K H 3 Replies Last reply
    0
    • L lisoft

      Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample: CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); } I'm sure the absolute file path/name is correct and have read/write permission to the file location. When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.

      Lisoft

      N Offline
      N Offline
      nisha00000
      wrote on last edited by
      #2

      CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.fOpen(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); } Try this.. Actually CstdioFile used for creating file in runtime so u ll modify above ..

      L 1 Reply Last reply
      0
      • N nisha00000

        CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.fOpen(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); } Try this.. Actually CstdioFile used for creating file in runtime so u ll modify above ..

        L Offline
        L Offline
        lisoft
        wrote on last edited by
        #3

        You mean replace m_file.Open() with m_file.fOpen()? What is fOpen?

        Lisoft

        N 1 Reply Last reply
        0
        • L lisoft

          You mean replace m_file.Open() with m_file.fOpen()? What is fOpen?

          Lisoft

          N Offline
          N Offline
          nisha00000
          wrote on last edited by
          #4

          its just try ..if it is that create run time u may be add fopen

          1 Reply Last reply
          0
          • L lisoft

            Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample: CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); } I'm sure the absolute file path/name is correct and have read/write permission to the file location. When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.

            Lisoft

            K Offline
            K Offline
            krmed
            wrote on last edited by
            #5

            The way you show your m_filename is not an absolute path, but a relative path. When you run from within VS (Ctrl_F5) the default working directory is the same folder as your .sln/.vcproj file. Let's say it's "MyProg", thefore you would attempt to open the file in VS, the path would be

            MyProg\some absolute file path\name

            However, if you run it from the Windows Explorer (double click on it) the default directory would be the location of the .exe. In this case, it might be

            MyProg\debug\some absolute file path\name

            The CStdioFile.Open will not create directories if the don't exist, and that would cause it to fail. Perhaps if you show the actual contents of your m_filename it may be helpful. Hope that helps.

            Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

            L 1 Reply Last reply
            0
            • K krmed

              The way you show your m_filename is not an absolute path, but a relative path. When you run from within VS (Ctrl_F5) the default working directory is the same folder as your .sln/.vcproj file. Let's say it's "MyProg", thefore you would attempt to open the file in VS, the path would be

              MyProg\some absolute file path\name

              However, if you run it from the Windows Explorer (double click on it) the default directory would be the location of the .exe. In this case, it might be

              MyProg\debug\some absolute file path\name

              The CStdioFile.Open will not create directories if the don't exist, and that would cause it to fail. Perhaps if you show the actual contents of your m_filename it may be helpful. Hope that helps.

              Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

              L Offline
              L Offline
              lisoft
              wrote on last edited by
              #6

              Thanks for your help, but I'm always looking into the m_filename and I'm sure that was absolute. Something newly found today that when I call m_file.Open() I got an warnning message:Warning: could not get volume information 'd:\Documents and Settings\mmn7xxl\My Documents\My Project\Program\WareHouseReport\"d:\' . Can you figure this out for me?

              Lisoft

              K 1 Reply Last reply
              0
              • L lisoft

                Thanks for your help, but I'm always looking into the m_filename and I'm sure that was absolute. Something newly found today that when I call m_file.Open() I got an warnning message:Warning: could not get volume information 'd:\Documents and Settings\mmn7xxl\My Documents\My Project\Program\WareHouseReport\"d:\' . Can you figure this out for me?

                Lisoft

                K Offline
                K Offline
                krmed
                wrote on last edited by
                #7

                That string can't really be a file name.

                lisoft wrote:

                d:\Documents and Settings\mmn7xxl\My Documents\My Project\Program\WareHouseReport\"d:\

                Show the actual code where you build that string and maybe we can help.

                Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

                1 Reply Last reply
                0
                • L lisoft

                  Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample: CString m_filename="some absolute file path\name"; CStdioFile m_file; if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite)) { AfxMesageBox (_T("Can not open the file")); } I'm sure the absolute file path/name is correct and have read/write permission to the file location. When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.

                  Lisoft

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  Maybe you have this file, can you show path?

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups