INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help with seldirdlg() function

Help with seldirdlg() function

(OP)
Help with seldirdlg() function

I had been using this function by M Gagnon for years before I stopped programming.
I have just put together a new small utility and I find this functions dlg starts at My PC on my Win 10 machine.
I have to access the network so how can I start higher up?

CODE

FUNCTION SelDirDlg
LPARAMETERS cDialogTitle, cStartingFolder, nBrowseFlags
*  Select a directory using the default browser dialog
*  Give a default title if none specified
IF TYPE('cDialogTitle') # 'C'
    cDialogTitle = 'Please select a folder:'
ENDIF
*  Default the start folder to an empty string;  if
*  you specify a starting folder, the browse is
*  anchored there, although you can override it with
*  the dialog's EditBox
IF TYPE('cStartingFolder') # 'C'
    cStartingFolder = ''
ENDIF
IF TYPE('nBrowseFlags') # 'N'
    * uses BROWSEINFO structure ulFlags values
    * by default, set BIF_RETURNONLYFSDIRS (1) and BIF_EDITBOX (16) and BIF_VALIDATE
    * to limit to returning directories, provide an edit box to let user enter a path,
    * and validate manually-entered paths
    *
    * ulFlags values:
    *    BIF_RETURNONLYFSDIRS    1
    *    BIF_DONTGOBELOWDOMAIN    2
    *    BIF_STATUSTEXT            4
    *    BIF_RETURNFSANCESTORS    8
    *    BIF_EDITBOX                0x10
    *    BIF_VALIDATE            0x20
    *    BIF_BROWSEFORCOMPUTER    0x1000
    *    BIF_BROWSEFORPRINTER    0x2000
    *    BIF_BROWSEFOREVERYTHING    0x4000
    nBrowseFlags = 32 + 16 + 1
ENDIF
LOCAL oBrowseObject, cPathToReturn, oShellObj
oShellObj = CREATEOBJ('Shell.Application')
cPathToReturn = ''
*    Get a Folder object
oBrowseObject = oShellObj.BrowseForFolder(0, ;
        cDialogTitle, ;
        nBrowseFlags, ;
        cStartingFolder)
*    Before I used the Items collection of the Folder object
*    to get a path;  it doesn't work if the directory is empty.
*    Instead, spin through the Items collection of the Parent
*    Folder and locate the item whose name matches the
*    Title property of the Folder object;  return that path
IF TYPE('oBrowseObject') = 'O' AND ! ISNULL(oBrowseObject)
    FOR EACH item IN oBrowseObject.ParentFolder.Items
        IF item.name == oBrowseObject.title
            cPathToReturn = Item.Path
            EXIT
        ENDIF
    ENDFOR
ENDIF
RETURN cPathToReturn 
Thanks
GenDev

RE: Help with seldirdlg() function

I think is just a question of specifying a starting folder sufficiently high up the file system.

Instead of passing cStartingFolder as the fouth parameter to BrowseForFolder(), try passing the number 18. (I know this is numeric and the required folder name is a string, but it should work.)

18 is the value the ssfNETWORK constant, which represents the root of the network namespace hierarchy. If 18 doesn't work, try some of the other constants listed here: https://msdn.microsoft.com/en-us/library/windows/d...

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Help with seldirdlg() function

I'd just use the BIF_BROWSEFOREVERYTHING flag additional to the already used flags in the line nBrowseFlags = 32 + 16 + 1

This actually is nBrowseFlags = BIF_VALIDATE + BIF_EDITBOX + BIF_RETURNONLYFSDIRS + BIF_BROWSEFOREVERYTHING and you most likely need to skip BIF_RETURNONLYFSDIRS to also return a network location.

Then you need to find out whether that actually will help you get some path you can work with in UNC notation, for example. If not, and perhaps even without trying, you're better off by mapping network shares to drive letters.

Bye, Olaf.

RE: Help with seldirdlg() function

(OP)
Mike,

Unfortunately I still get the dialogue stuck on My PC when I pass numeral 18.
GenDev

RE: Help with seldirdlg() function

(OP)
Olaf,
I've messaged to use mapped drives on my form and of course it works like a charm.
I had tried BIF_BROWSEFOREVERYTHING by adding 4096 to the the line nBrowseFlags = 32 + 16 + 1 but it didn't change anything as far as I could tell.

Thanks

GenDev

RE: Help with seldirdlg() function

0x4000 is 16384, why don't you simply make use of the constants and don't work with the numbers? They are defined for a good reason to make clear what options are combined in the one flags value, plus you can't fail to make a wrong conversion to decimal. VFP understands 0x4000, simply do "? 0x4000" and see for yourself.

Bye, Olaf.

RE: Help with seldirdlg() function

GenDev,

Sorry my solution didn't work for you. I just tried your code myself, and passing 18 did indeed cause the dialogue to open at the network level. But there might well be operating system differences or other factors at work.

Anyway, it's good that you now have a solution.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close