5,557,686 members and growing! (14,477 online)
Email Password   helpLost your password?
General Reading » Hardware & System » System     Intermediate License: The Creative Commons Attribution-ShareAlike 2.5 License

Map Network Drive (API)

By aejw

Class for interfacing to the "map network drive" windows interface
C#Windows, .NET, .NET 1.1, Win2K, WinXP, Win2003VS.NET2003, Visual Studio, Dev

Posted: 24 Apr 2004
Updated: 18 May 2004
Views: 139,987
Bookmarked: 55 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
41 votes for this Article.
Popularity: 6.77 Rating: 4.20 out of 5
4 votes, 9.8%
1
0 votes, 0.0%
2
3 votes, 7.3%
3
9 votes, 22.0%
4
25 votes, 61.0%
5

Image - netdrive0015.jpg

What does it do?

This is a class for interfacing with windows map network drive API's.

Introduction to the class...

  • Getting started

    Add the class file "cNetworkDrives0015.cs" to your project / solution.
    Add the "using" definition to your form, etc.
    using aejw.Network;
  • Example (Mapping a network drive)

     NetworkDrive oNetDrive = new aejw.Network.NetworkDrive();
     try{
        oNetDrive.LocalDrive = "m:";
        oNetDrive.ShareName = "\\ComputerName\Share"
        oNetDrive.MapDrive();
     }catch(Exception err){
        MessageBox.Show(this,"Error: "+err.Message);
     }
     oNetDrive = null;
  • Example (Unmapping a network drive)

     NetworkDrive oNetDrive = new aejw.Network.NetworkDrive();
     try{
        oNetDrive.LocalDrive = "m:";
        oNetDrive.UnMapDrive();
     }catch(Exception err){
        MessageBox.Show(this,"Error: "+err.Message);
     }
     oNetDrive = null;

Username and Password functions...

The following examples require the object / class to be declared.
     cNetworkDrive oNetDrive = new cNetworkDrive();
  • Mapping a network drive

    • //Map drive with current user credentials
      
      oNetDrive.LocalDrive = "m:";
      oNetDrive.ShareName = "\\ComputerName\Share1"
      oNetDrive.MapDrive();
    • //Map drive with specified user credentials
      
      oNetDrive.LocalDrive = "m:";
      oNetDrive.ShareName = "\\ComputerName\Share1"
      oNetDrive.MapDrive("Bob_Username","Bob_Password");
    • //Map drive with and prompt user for credentials
      
      oNetDrive.LocalDrive = "m:";
      oNetDrive.ShareName = "\\ComputerName\Share1"
      oNetDrive.PromptForCredentials = true;
      oNetDrive.MapDrive();
    • //Map drive using a persistent connection
      
      oNetDrive.LocalDrive = "m:";
      oNetDrive.Persistent = true;
      oNetDrive.SaveCredentials = true;
      oNetDrive.ShareName = "\\ComputerName\Share1"
      oNetDrive.MapDrive("Bob_Username","Bob_Password");
  • Unmapping a network drive

    • //Unmap a network connection
      
      oNetDrive.LocalDrive = "m:";
      oNetDrive.ShareName = "\\ComputerName\Share1"
      oNetDrive.UnMapDrive();
    • //Unmap a network connection ignoring network related errors
      
      oNetDrive.LocalDrive = "m:";
      oNetDrive.Force = true;
      oNetDrive.ShareName = "\\ComputerName\Share1"
      oNetDrive.UnMapDrive();
  • Other functions

    • //Display windows connection dialog
      
      oNetDrive.ShowConnectDialog(this);
      //Display windows disconnection dialog
      
      oNetDrive.ShowDisconnectDialog(this);
    • //Restore all persistent connections
      
      oNetDrive.RestoreDrives();

History

  • 14th May 2004 - build0015
    • LocalDrive and ShareName are now properties.
    • Dialog functions now use a form object instead of a window handle.
    • Renaming scheme for public functions and properties, MapNetworkDrive(...) is now MapDrive(...), etc...
    • Added Persistant option, Used for reconnecting a drive at logon.
    • Added SaveCredentials option, Allows windows to remember the user credentials when reconnecting a persistent connection.
    • Added Force option, for MapDrive calls, if a drive is connected it will disconnect that drive then reconnect to the new share.
    • Added PromptForCredintals option, for MapDrive calls, windows will ask for a username and password to use with the connection.
    • Added RestoreDrives function that restores persistent connections.
  • 30th April 2004 - build0012
    • Code refinements and tidying, added comments to the class.
  • 27th April 2004 - build0011
    • Adjusted declare tags, tidied class and article
  • 26th April 2004 - build0010
    • First version posted online

License

This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License

About the Author

aejw


C#, VB.net (Web and forms), SQL Server, MySQL, ASP, Win32 API, ...
Site: aejw.com
Occupation: Web Developer
Location: New Zealand New Zealand

Other popular Hardware & System articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 79 (Total in Forum: 79) (Refresh)FirstPrevNext
Subject  Author Date 
Questionproblem using in an aspx buttonmemberraziel781:58 2 Oct '08  
QuestionWorks on Windows XP Home?memberHugo Tomas3:51 10 Jul '08  
AnswerRe: Works on Windows XP Home?memberaejw15:58 20 Jul '08  
GeneralHow do you install programmemberchris guajardo11:50 18 Jun '08  
AnswerRe: How do you install program [modified]memberaejw12:59 19 Jun '08  
QuestionMultiple connections ExceptionmemberNickKa11:32 21 May '08  
AnswerRe: Multiple connections Exceptionmemberaejw0:38 20 Jun '08  
GeneralMap netdriver error. [modified]memberPaul Zhang17:24 16 Mar '08  
GeneralRe: Map netdriver error.memberaejw12:52 17 Mar '08  
GeneralRe: http webdrive (webdav) possible ?memberMatterz2:09 11 Nov '07  
GeneralRe: http webdrive (webdav) possible ?memberaejw6:40 11 Nov '07  
GeneralRe: http webdrive (webdav) possible ?memberMatterz18:31 26 Jan '08  
Generalhttp webdrive (webdav) possible ?memberMatterz12:04 10 Nov '07  
GeneralRe: http webdrive (webdav) possible ?memberaejw18:54 10 Nov '07  
GeneralUnmapping ErrormemberSturges6:12 9 Nov '07  
GeneralRe: Unmapping Errormemberaejw19:00 10 Nov '07  
GeneralRe: Unmapping ErrormemberSturges9:19 13 Nov '07  
GeneralThank youmemberMaYo693:36 28 Sep '07  
GeneralUnMapDrive [modified]memberDaniel B.6:55 18 Jun '07  
GeneralRe: UnMapDrivememberaejw19:36 20 Jun '07  
GeneralThanksmemberspockxx16:44 13 Dec '06  
GeneralFor Update....memberSixcode3:47 29 Oct '06  
GeneralWorking with VB.NET [modified]memberdietercools13:58 10 Sep '06  
GeneralReconnect DrivesmemberFeLiZk1:14 19 Aug '06  
GeneralRe: Reconnect Drivesmemberaejw22:13 20 Aug '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 May 2004
Editor: Nishant Sivakumar
Copyright 2004 by aejw
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project