Solved

specify or browse a folder on a network drive

Posted on 1998-11-22
7
188 Views
Last Modified: 2010-05-03
I would like to specify a folder on a network drive in a visual basic program I am writing. I cannot use a common dialog because the folder may not have any files in it, or I may want to create a new folder on the network drive, with no files in it. I would like to use an interface similar to a common dialog open form or network neighborhood. Any help would be appreciated.
0
Comment
Question by:cliff_martin
7 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1446191
Umm, you *can* use the CommonDialog. It just requires the filename field to be non-blank before the OK button will work. If the user is in an empty directory they can just type X or something and click [OK] and it will return without a problem unless you've got the FileMustExist flag set. If you enable [Cancel] error trap I *think* it will return whatever directory the user has changed to in .FileName

Alternative is to use drive and directory boxes or "roll your own" common dialog box.

M

0
 

Author Comment

by:cliff_martin
ID: 1446192
The common dialog open does not work well. I try to select a directory and end up selecting the directory above it because it I did not click on the whitespace to select directory (if you can follow that, I am impressed). What I am trying to say is that while it does work, it can be confusing to the user. I would be interested in any help in "rolling my own" as you say, though. thanks
0
 
LVL 3

Expert Comment

by:jjbyers
ID: 1446193
Do you want to connect to a network drive or just get a path to a drive already connected?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:cliff_martin
ID: 1446194
I want to be able to browse all available network shares, not just mapped drives.
0
 
LVL 3

Accepted Solution

by:
jjbyers earned 30 total points
ID: 1446195
This is the code I use to show the explorer map/disconnect drive dialog box.

Public Const RESOURCETYPE_DISK = &H1

Public Declare Function WNetConnectionDialog Lib "mpr.dll" _
   (ByVal hwnd As Long, ByVal dwType As Long) As Long
   
Public Declare Function WNetDisconnectDialog Lib "mpr.dll" _
   (ByVal hwnd As Long, ByVal dwType As Long) As Long

Public Sub ShowMapDriveDlg(pfrmParent As Form)
'*********************************************************
'* Purpose: Shows the networking map drive letter dialog
'*
'* Input Parameters: pfrmParent - Parent form name
'*
'* Returns: None
'*
'* Called Routines: None
'*********************************************************
  'If the function succeeds, the return value is
  'NO_ERROR (0). If the user cancels out of the
  'dialog box, it is &HFFFFFFFF.
             
  'Passing the form as the hwnd displays the
  'dialog modally to that form.  Pass 0& to
  'make the parent the desktop.
 
  'Setup error trapping
  On Error GoTo MapDrive_Error
 
  Call WNetConnectionDialog(pfrmParent.hwnd, RESOURCETYPE_DISK)
 
  'No Error Exit
  Exit Sub
 
MapDrive_Error:
  'Show Error
  MsgBox "Error in ShowMapDriveDlg of " & Err.Description & " " & Err.Number, vbOKOnly + vbCritical, App.ProductName
End Sub
     
Public Sub ShowDisconnectDriveDlg(pfrmParent As Form)
'*********************************************************
'* Purpose: Shows the networking Disconnect drive dialog
'*
'* Input Parameters: pfrmParent - Parent form name
'*
'* Returns: None
'*
'* Called Routines: None
'*********************************************************
  'If the function succeeds, the return value is
  'NO_ERROR (0). If the user cancels out of the
  'dialog box, it is &HFFFFFFFF.
             
  'Passing the form as the hwnd displays the
  'dialog modally to that form.  Pass 0& to
  'make the parent the desktop.
 
  'Setup error trapping
  On Error GoTo DisconnectDrive_Error
 
  Call WNetDisconnectDialog(pfrmParent.hwnd, RESOURCETYPE_DISK)
 
  'No Error Exit
  Exit Sub
 
DisconnectDrive_Error:
  'Show Error
  MsgBox "Error in ShowDisconnectDriveDlg of " & Err.Description & " " & Err.Number, vbOKOnly + vbCritical, App.ProductName
End Sub

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446196
Bought This Question.
0
 

Expert Comment

by:soyapi
ID: 3335252
You just can map\connect to the other computer, but not on NT Server, I got Access Deny though I supply the right password, still access deny.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now