Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with seldirdlg() function 1

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU
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
 
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:
Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I'd just use the [tt]BIF_BROWSEFOREVERYTHING[/tt] flag additional to the already used flags in the line [tt]nBrowseFlags = 32 + 16 + 1[/tt]

This actually is [tt]nBrowseFlags = BIF_VALIDATE + BIF_EDITBOX + BIF_RETURNONLYFSDIRS + BIF_BROWSEFOREVERYTHING[/tt] 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.
 
Mike,

Unfortunately I still get the dialogue stuck on My PC when I pass numeral 18.
GenDev
 
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
 
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top