Common Dialog OpenFile - Default Folder To Browse?

Jonathan2708Jonathan2708 Member Posts: 552
Hi,

I'm using Codeunit 412 Common Dialog Management to prompt the user for a file. My question is can you set the OpenFile function to popup the window in a specific folder via code? You can give it a default filename, but can't see how to set a default folder.

If not is there a workaround, maybe another function to call first to set the users' default folder?

Any help appreciated,

Jonathan

Answers

  • kapamaroukapamarou Member Posts: 1,152
    In 412 you'll see:

    CommonDialogControl.InitDir := DefaultFileName;

    I guess it takes the path of the file you pass as a parameter.

    Either pass your parameter differently or

    copy the function as OpenFile2, add a parameter defDir and change the line to :
    CommonDialogControl.InitDir := defDir;


    Try it to see if it works...
  • Jonathan2708Jonathan2708 Member Posts: 552
    Hi,

    Thanks for the reply but already tried that. It simply uses the parameter as a default filename, not folder, and if you specify a backslash e.g. 'C:\WINDOWS\' then you get an error message.

    Jonathan
  • kapamaroukapamarou Member Posts: 1,152
    I tried it like this:


    I Copied OpenFile to new function OpenFile2.

    I added one more parameter defdir (text 30);

    I found the line:
    CommonDialogControl.InitDir := DefaultFileName;
    
    and changed it to:
    CommonDialogControl.InitDir := defdir;
    

    Then to call the function I do the following:
    cu412.OpenFile2('Open','',0,'',0,'C:\program files\adobe');
    

    Did you try it like this? When I run it it opens folder C:\program files\adobe with a blank filename.
  • Jonathan2708Jonathan2708 Member Posts: 552
    Thanks, I've sussed it. The default folder only works if you set the default filename to blank ''.

    Thanks for your help,

    Jonathan
  • kapamaroukapamarou Member Posts: 1,152
    You're welcome. :D
  • kapamaroukapamarou Member Posts: 1,152
    The default folder only works if you set the default filename to blank

    I tried it and it also works if you pass as a filename 'file.txt' for example, along with the path parameter...
Sign In or Register to comment.