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. How do I Set the default Location for Saving Files??

How do I Set the default Location for Saving Files??

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 Posters 2 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.
  • U Offline
    U Offline
    User 11708363
    wrote on last edited by
    #1

    Hi, I have a Single Doc, Multiple views Application and I have a Menu option called "options" which accepts the Default location to Save Files. How do I set the Default Location ?What is the Function used and How do I use it? so that, when the user says File->Save, it should show the deafault directory to save the file. Any Suggestions... Thank you Priya

    L S 2 Replies Last reply
    0
    • U User 11708363

      Hi, I have a Single Doc, Multiple views Application and I have a Menu option called "options" which accepts the Default location to Save Files. How do I set the Default Location ?What is the Function used and How do I use it? so that, when the user says File->Save, it should show the deafault directory to save the file. Any Suggestions... Thank you Priya

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try this code [CODE]
      OPENFILENAME ofn;
      char defaultFileName[MAX_PATH + 1] = "Default file name";
      char szFileTitle[MAX_PATH + 1];
      ofn.lStructSize = sizeof(OPENFILENAME);
      ofn.hwndOwner = NULL;
      ofn.hInstance = GetModuleHandle(NULL);
      ofn.lpstrFilter = "All Files (*.*)\0*.*\0\0";
      ofn.lpstrCustomFilter = (LPTSTR) NULL;
      ofn.nMaxCustFilter = 0L;
      ofn.nFilterIndex = 1L;
      ofn.lpstrFile = defaultFileName;
      ofn.nMaxFile = sizeof(defaultFileName);
      ofn.lpstrFileTitle = szFileTitle;
      ofn.nMaxFileTitle = MAX_PATH;
      ofn.lpstrInitialDir = "C:\\DefaultDir";
      ofn.lpstrTitle = __TEXT("Save Da Doc as...");
      ofn.nFileOffset = 0;
      ofn.nFileExtension = 0;
      ofn.lpstrDefExt = NULL;
      ofn.lCustData = 0;
      ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_LONGNAMES;
      int result = GetSaveFileName(&ofn);
      if (result == IDOK) {
      MessageBox(defaultFileName,"Full Path is ");
      MessageBox(szFileTitle,"File Name only is ");
      }
      [CODE] Note There is also easier ways with MFC ... :D Hope It will help ALfadhly

      1 Reply Last reply
      0
      • U User 11708363

        Hi, I have a Single Doc, Multiple views Application and I have a Menu option called "options" which accepts the Default location to Save Files. How do I set the Default Location ?What is the Function used and How do I use it? so that, when the user says File->Save, it should show the deafault directory to save the file. Any Suggestions... Thank you Priya

        S Offline
        S Offline
        solex
        wrote on last edited by
        #3

        SetCurrentDirectory The SetCurrentDirectory function changes the current directory for the current process. BOOL SetCurrentDirectory( LPCTSTR lpPathName // pointer to name of new current directory ); Parameters lpPathName Pointer to a null-terminated string that specifies the path to the new current directory. This parameter may be a relative path or a fully qualified path. In either case, the fully qualified path of the specified directory is calculated and stored as the current directory. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks Each process has a single current directory made up of two parts: A disk designator that is either a drive letter followed by a colon, or a server name and share name (\\servername\sharename) A directory on the disk designator

        L 1 Reply Last reply
        0
        • S solex

          SetCurrentDirectory The SetCurrentDirectory function changes the current directory for the current process. BOOL SetCurrentDirectory( LPCTSTR lpPathName // pointer to name of new current directory ); Parameters lpPathName Pointer to a null-terminated string that specifies the path to the new current directory. This parameter may be a relative path or a fully qualified path. In either case, the fully qualified path of the specified directory is calculated and stored as the current directory. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks Each process has a single current directory made up of two parts: A disk designator that is either a drive letter followed by a colon, or a server name and share name (\\servername\sharename) A directory on the disk designator

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          SetCurrentDirectory Changes the current directory for the current process This means that if your program is writting to temporary files or reading from other files you will be effecting the location of all subsequent File I/O operations which you don't specify the Exact Directory location for. Do you really want to do that.? Alfadhly

          S 1 Reply Last reply
          0
          • L Lost User

            SetCurrentDirectory Changes the current directory for the current process This means that if your program is writting to temporary files or reading from other files you will be effecting the location of all subsequent File I/O operations which you don't specify the Exact Directory location for. Do you really want to do that.? Alfadhly

            S Offline
            S Offline
            solex
            wrote on last edited by
            #5

            No this means that you do a GetCurrentDirectory SetCurrentDirectory, do your file saving and return to the directory that you retrieved with GetCurrentDirectory. But anyway, as you never can be sure what the current directory is, unless you set it yourself,you should never try to read/write without an exact directory location and temorary files should go into the TEMP variable or the winnt\system.

            B 1 Reply Last reply
            0
            • S solex

              No this means that you do a GetCurrentDirectory SetCurrentDirectory, do your file saving and return to the directory that you retrieved with GetCurrentDirectory. But anyway, as you never can be sure what the current directory is, unless you set it yourself,you should never try to read/write without an exact directory location and temorary files should go into the TEMP variable or the winnt\system.

              B Offline
              B Offline
              Blake Miller
              wrote on last edited by
              #6

              You will be pleasantly surprised to find that Windows Terminal Services Edition might prevent you from writing altogether to the Windows\System folder. There is a call to obtain the temporary directory that should be used, I think it is GetTempDirectory(). Since Windows 2000 might allow multiple logons, I have noticed that the temporary directory is different for each user.

              L 1 Reply Last reply
              0
              • B Blake Miller

                You will be pleasantly surprised to find that Windows Terminal Services Edition might prevent you from writing altogether to the Windows\System folder. There is a call to obtain the temporary directory that should be used, I think it is GetTempDirectory(). Since Windows 2000 might allow multiple logons, I have noticed that the temporary directory is different for each user.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                True Blake, This is the same reason a copy of Office 97 will not work on Win2000

                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