Solved

specify or browse a folder on a network drive

Posted on 1998-11-22
7
194 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
[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
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 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