?
Solved

API to show folder dialog with ONLY Network Folders or ONLY Local folders

Posted on 2005-03-25
3
Medium Priority
?
401 Views
Last Modified: 2012-05-05
Hello !

I need to provide user with two dialog boxes. First has ONLY local (i.e hide all network folders) and second - ONLY network folders.
I use VB6 + SP2, target OS is Win XP. I want pure API solutions that work OK for all Win XP (and if possible Win 2000 + SP4)
0
Comment
Question by:dvplayltd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13634299
go to http:\\vbnet.mvps.org or www.allapi.net and search around on there, they have great examples with coding to show you a bunch of things :)
0
 

Author Comment

by:dvplayltd
ID: 13635123
I prefer to use  API SHBrowseForFolder, however I can NOT find flags that will limit folders to network or local.
0
 
LVL 4

Accepted Solution

by:
rdwillett earned 1000 total points
ID: 13635202
Will take a jab at this and you can change it however  u want


Add Three text boxes named Text1 and Text2 and Text3
Add Three command buttons named Command1 and Command2 and Command3
Command1 returns only a valid network server or workstation including shares
Command2 returns all drives
Command3 only returns local drives
Add the following code to form and run project

Also refer to this website: http://vbnet.mvps.org/index.html?code/browse/browseoverview.htm

Option Explicit
Private Const ERROR_SUCCESS As Long = 0
Private Const MAX_PATH As Long = 260
Private Const CSIDL_NETWORK As Long = &H12
Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
Private Const CSIDL_DRIVES As Long = &H11


Private Type BROWSEINFO
   hOwner As Long
   pidlRoot As Long
   pszDisplayName As String
   lpszTitle As String
   ulFlags As Long
   lpfn As Long
   lParam As Long
   iImage As Long
End Type
 
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
   Alias "SHGetPathFromIDListA" _
  (ByVal pidl As Long, _
   ByVal pszPath As String) As Long
 
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
   Alias "SHBrowseForFolderA" _
  (lpBrowseInfo As BROWSEINFO) As Long
 
Private Declare Function SHGetSpecialFolderLocation _
   Lib "shell32.dll" _
  (ByVal hwndOwner As Long, _
   ByVal nFolder As Long, _
   pidl As Long) As Long
   
Private Declare Sub CoTaskMemFree Lib "ole32.dll" _
   (ByVal pv As Long)
Private Sub Command1_Click()
   Text1.Text = GetBrowseNetworkWorkstation()
End Sub
Private Sub Command2_Click()
   Text2.Text = GetBrowseNetworkShare()
End Sub
Private Sub Command3_Click()
   Text3.Text = GetLocal()
End Sub
Private Function GetBrowseNetworkShare() As String
    'returns only a valid share on a network server or workstation
    Dim BI As BROWSEINFO
    Dim pidl As Long
    Dim sPath As String
    Dim pos As Integer
 
    If SHGetSpecialFolderLocation(Me.hWnd, _
                                 CSIDL_NETWORK, _
                                 pidl) = ERROR_SUCCESS Then
       
        With BI
            .hOwner = Me.hWnd
            .pidlRoot = pidl
            .pszDisplayName = Space$(MAX_PATH)
            .lpszTitle = "Select a network computer or share."
            .ulFlags = BIF_RETURNONLYFSDIRS
        End With
         
        pidl = SHBrowseForFolder(BI)
        If pidl <> 0 Then
            sPath = Space$(MAX_PATH)
            If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
                pos = InStr(sPath, Chr$(0))
                GetBrowseNetworkShare = Left$(sPath, pos - 1)
            End If
            Call CoTaskMemFree(pidl)
        Else:
            GetBrowseNetworkShare = "\" & BI.pszDisplayName
        End If
    End If
End Function
Private Function GetMyComputer() As String
    'returns all computer drives
    Dim BI As BROWSEINFO
    Dim pidl As Long
    Dim sPath As String
    Dim pos As Integer
   
    If SHGetSpecialFolderLocation(Me.hWnd, _
                                 BIF_BROWSEFORCOMPUTER, _
                                 pidl) = ERROR_SUCCESS Then
       
       
        With BI
            .hOwner = Me.hWnd
            .pidlRoot = pidl
            .pszDisplayName = Space$(MAX_PATH)
            .lpszTitle = "Select a network computer."
            .ulFlags = BIF_BROWSEFORCOMPUTER
        End With
         

        If SHBrowseForFolder(BI) <> 0 Then
            GetMyComputer = "\" & BI.pszDisplayName
        End If
        Call CoTaskMemFree(pidl)
    End If
End Function

Private Function GetLocal() As String
    'returns all local computer drives
    Dim BI As BROWSEINFO
    Dim pidl As Long
    Dim sPath As String
    Dim pos As Integer
   
    If SHGetSpecialFolderLocation(Me.hWnd, _
                                 CSIDL_DRIVES, _
                                 pidl) = ERROR_SUCCESS Then
       
        With BI
            .hOwner = Me.hWnd
            .pidlRoot = pidl
            .pszDisplayName = Space$(MAX_PATH)
            .lpszTitle = "Select a network computer."
            .ulFlags = BIF_BROWSEFORCOMPUTER
        End With
         
        If SHBrowseForFolder(BI) <> 0 Then
            GetLocal = "\" & BI.pszDisplayName
        End If
        Call CoTaskMemFree(pidl)
    End If
End Function

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question