Customizing the PathEdit and DirectoryCombo controls to validate path entries

My last post Common Tasks: Validating a Path received this comment from HookEm:

 Two of your 5 conditions can be handled without a custom action using the native MSI controls:

"Must be less than 200 characters in length": see the Text property of the PathEdit control (msdn.microsoft.com/.../aa370749(VS.85).aspx)

"must be on a fixed (local, non-removable) drive": see the available hexadecimal bit flags assignable to the Attributes property of the DirectoryCombo control (msdn.microsoft.com/.../aa368290(VS.85).aspx)

 -----------------------------------------

This was great information! Thanks, HookEm! Please keep the comments coming Smile

I checked out the PathEdit control.

You can put {200} (for example) in the Text field and that will prevent the user from manually typing in more than 200 characters. For most purposes this will work perfectly fine.

However, there are some aspects about how the dialog works that you may want to be aware of. These are mostly corner case situations, but your QA team may run across them in their testing, so just wanted you to be aware of them.

  • When you click OK, the InstallShield SetTargetPath function will then append a backslash to the path - giving a length of 201. 
  • If you then click the Change.. button to go back into the dialog, you will get an error that the path is too long, because now it is 201, not 200.
  • Also, from the dialog itself, if you use the new folder button it makes a folder called "New Folder". If that puts your path over the limit, you get an error, BUT it goes ahead and creates the folder anyway. The path showing in the PathEdit field is the truncated path, but if you click OK from the dialog it actually sets the path to the long path including the New Folder. SO.. it's possible to leave the dialog having set the path to a length longer that your desired limit.
  • It's possible to get into a state on the dialog where the INSTALLDIR value is out of synch with the path in the PathEdit field.

 

I also checked out the Directory Combo control.

Very good to know! I hadn't looked at this control's extra settings before. From the Dialog editor UI in InstallShield you can set each type of drive, Fixed, Removeable, RAMDisk, Remote, etc. to TRUE or FALSE in that combo box. Making that change will immediately reduce the likelihood of a person selecting a disalowed drive type.

Note, however, that the user is still free to type into the PathEdit box a path that uses a drive of that type. So this does help, but doesn't completely cover the situation.

 

One thing to note is that using just these settings you can't validate the path unless the user is using the UI. If you use a custom action and table to validate the path length, then you can validate the path during the Execution phase, even if the installation is being done without UI. So, I'd recommend using these settings in conjunction with a path validation custom action. I think they complement each other. 

 

Published Tuesday, May 20, 2008 9:26 AM by SusanGorman

Comments

No Comments