Solved

specify or browse a folder on a network drive

Posted on 1998-11-22
7
187 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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