cancel
Showing results for 
Search instead for 
Did you mean: 

GetFileOpenName default location is different for short filename and long filenames

Former Member
0 Kudos

We use GetFileOpenName PB built-in function to find PDF files. The initdir variable passed to this function was a short file name (ex. C:\PROGRA~1\TEMP). The behavior of the default starting folder was as expected and as described with the hierarchy in windows 7. The hierarchy being last known open/save folder location is "saved" (do not know where) and used if one is found else the application uses C:\PROGRA~1\TEMP as default location. The last save/open information is retained even after exiting the application.

Our network staff was dropping the support for short file names and we changed the filenames to NTFS. So when calling the GetFileOpenName, we send "C:\Program Files\TEMP" value to the initdir variable. Now the last known open/save folder location is not being defaulted to anymore.

Is there a way to find this "saved" location? Why would sending a short file name work and not a NTFS name?

Got the application to function the same way by sending the GetCurrentDirectory() as the initdir. But this is limited to only that session of the application. Once the user exits the application the last open save location is gone with it.

Tried searching the REGISTRY for the location (by string searching for last location). No luck. If this is saved by PB, what is the registry key? If not a registry entry then where can this be found?

I know there are fileIO windows API calls that give better control. However, the built in PB function retains the last open/save location even after you have exited the application. Short of saving this information off somewhere (DB or user profile), would like to get at this information if it is accessible.

Environments: PB 12.5.1 build 4595, OS - windows 7.

Any help would be greatly appreciated. Thank you. SM.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Sai;

  FYI: The GetFileOpenName ( ) method was updated in recent PB releases to include two new parameters  { , initdir { , aFlag } } - where ...

initdir     A string whose value is the initial directory name.

aFlag     An unsigned long whose value determines which options are enabled in the dialog box.

aFlag values:

1    OFN_CREATEPROMPT    If the specified file does not exist, prompt for permission to create the file. If the user chooses to create the file, the dialog box closes; otherwise the dialog box remains open.

2    OFN_EXPLORER    Use an Explorer-style dialog box.

3    OFN_EXTENSIONDIFFERENT    The file extension entered differed from the extensions specified in extension.

4    OFN_FILEMUSTEXIST    Only the names of existing files can be entered.

5    OFN_HIDEREADONLY    Hide the Read Only check box.

6    OFN_LONGNAMES    Use long file names. Ignored for Explorer-style dialog boxes.

7    OFN_NOCHANGEDIR    Restore the current directory to its original value if the user changed the directory while searching for files. This option has no effect for GetFileOpenName on Windows NT, 2000, and XP.

8    OFN_NODEREFERENCELINKS    Return the path and file name of the selected shortcut (.lnk file); otherwise the path and file name pointed to by the shortcut are returned.

9    OFN_NOLONGNAMES    Use short file names (8.3 format). Ignored for Explorer-style dialog boxes.

10    OFN_NONETWORKBUTTON    Hide the Network button. Ignored for Explorer-style dialog boxes.

11    OFN_NOREADONLYRETURN    The file returned is not read only and is not in a write-protected directory.

12    OFN_NOTESTFILECREATE    Do not create the file before the dialog box is closed. This option should be specified if the application saves the file on a netwrok share where files can be created but not modified. No check is made for write protection, a full disk, an open drive door, or network protection. A file cannot be reopened once it is closed.

13    OFN_NOVALIDATE    Invalid characters are allowed in file names.

14    OFN_OVERWRITEPROMPT    Used in Save As dialog boxes. Generates a message box if the selected file already exists.

15    OFN_PATHMUSTEXIST    Only valid paths and file names can be entered.

16    OFN_READONLY    Select the Read Only check box when the Save dialog box is created.

Are you using these?

Regards ... Chris

Former Member
0 Kudos

Chris,

We are using the new updated method. Tried several different options for the aFlag variable and none of them seem to retain the last open location when a long filename is passed to the initdir variable. Preference would be to use Explorer-style dialog with long filenames.

Thanks. SM.

Former Member
0 Kudos

1) retain the last open location

=> Yes, you would need to save that in your applications INI's file (or equivalent).

2) use Explorer-style dialog

=> aFlag = 2 OFN_EXPLORER - Use an Explorer-style dialog box.

For each option, the value of the aflag is 2^(index -1),   So for Explorer L&F plus with Long Names the aFlag would be ...

2^(2-1)    =    2

2^(10-1)  = 512

aFlag = 514

PS: Make sure that your work variable for the aFlag is a LONG datatype

HTH (works great for me)    

Former Member
0 Kudos

Chris,

Tried with aFlag = 514, 18 and other combinations as well. Just does not want to retain the last location. Will use GetCurrentDirectory() as initdir for now. Thanks for your help. SM.

Former Member
0 Kudos

I found where Windows stores the last location in the registry. It is by file extension, not program. The data is in a binary format so no chance of manipulating it yourself.

MRUKeys - winreg-kb - Most Recently Updated (MRU) Keys - Windows Registry Knowledge Base - Google Pr...

Former Member
0 Kudos

I have an example of the Windows API function:

Topwiz Software - GetFileName

Former Member
0 Kudos

Thanks Roland. Will look at this as a last option. My question though is does this code retain the last open/save location even after the application has ended?

Former Member
0 Kudos

There isn't any code I put in to save the last location. You could save that in the registry and then pass it back in the next time you call the function.

Former Member
0 Kudos

Thank you Roland. Will try that last.

Former Member
0 Kudos

This is just a suggestion: Save the folder/directory to registry or ini file so you don't have to rely on windows current directory. I think this is the best practice.