Using the Map WebDAV Drive API

With Map WebDAV Drive, you can programmatically mount a drive using the .Net Service API, include the Map WebDAV Drive to your installation program or build your own interface for drive mapping. The schema below shows components of Map WebDAV Drive:

IT Hit Map WebDAV Drive API schema

To start using the API, you will need the Map WebDAV Drive SDK and the evaluation license file. Both SDK and license file could be downloaded here. If you experience any problems the first thing to do is to examine the logfile called ITHit.MapWebDAVDrive.Service.Program.log created in C:\Windows\Temp folder.

Mounting Drive with Service API

Using the .Net Service API provided by IT Hit Map WebDAV Drive you can mount and unmount drives to your local file system. To use Service API the IT Hit Map WebDAV Drive (or merge module, see below) must be installed on the computer where Service API is used.

Mounting drive letter with Service API

Add a reference to ITHit.MapWebDAVDrive.Core.dll and ITHit.MapWebDAVDrive.ServiceClient.dll to your .Net project. Your application folder must also contain ITHit.MapWebDAVDrive.DataModel.dll and ITHit.WebDAV.Client.dll.

Then add following namespaces to your .cs file:

using ITHit.MapWebDAVDrive.Core;
using ITHit.MapWebDAVDrive.ServiceClient;
 

To mount a new drive create instance of DriveSettings class, get IDriveServiceManager interface and call AddDrive method:

DriveSettings driveSettings = new DriveSettings('z',
      new Uri("http://dav.webdavsystem.com/"), "User1", "pwd");
IDriveServiceManager manager = DriveManager.GetManager();
manager.AddDrive(driveSettings);

Pass drive letter, WebDAV server URL and login credentials to DriveSettings constructor.  In case of domain authentication, specify the user name in the DOMAIN\Login format.
To unmount the drive, call IDriveServiceManager.RemoveDrive method passing drive letter as a parameter:

manager.RemoveDrive('z');

Using the Merge Module in Your Setup Application

The IT Hit Map WebDAV Drive SDK provides the merge module that could be used in your setup application. The merge module installs file system driver, Windows service, Tray application and Windows Explorer Shell Extension on a target machine. It does not add any shortcuts to the Start / All Programs menu or desktop.

The BuildMsi sample provided with the SDK demonstrates how to use the merge modules to build x86 and x64 installation files.

After installing your application (or during custom action execution) you can set the license using Service API via IDriveServiceManager interface so that the registration wizard do not appear:

using ITHit.MapWebDAVDrive.ServiceClient;
...
string license = @"<?xml version='1.0' ...
IDriveServiceManager manager = DriveManager.GetManager();
manager.SetLicense(license);

You have to set the license only one time, after installation.

Important! The IT Hit Map WebDAV Drive cannot run side-by side with the application using the merge module. You must uninstall the IT Hit Map WebDAV Drive before installing your application. To detect if IT Hit Map WebDAV Drive is installed check the 'HKLM\Software\IT Hit\Map WebDAV Drive' registry key. 

Creating Your Own Drive Mounting Application Using Core API

Using the IT Hit Map WebDAV Drive Core API you can build your own interface for drive mapping. You will have to install the file system driver, reboot the computer, set license and create an instance of ActiveDrive class.

Mounting drive letter with Core API

  • Place all files contained in \SDK\x86\ to the folder where your application exe or dll resides (if you run 64-bit Windows use files from \SDK\x64\ folder).
  1. Add reference to ITHit.MapWebDAVDrive.Core.dll in your project and using directive:
    using ITHit.MapWebDAVDrive.Core;
  2. Install the file system driver and reboot the computer:
    Management.InstallDriver("MyDriveMappingAppID");
    System.Diagnostics.Process.Start("ShutDown", "/r /t 0");
    Pass unique application ID to InstallDriver method. Use this ID when uninstalling the driver with Management.UninstallDriver method.
  3. Set license:
    string license = @"<?xml version='1.0' ...
    Management.SetLicense(license);
    The license should be set each time you run your application, before drive mounting.
  4. Create an instance of ActiveDrive class and call Mount method. Pass drive letter, WebDAV server URL and login credentials to ActiveDrive class constructor:
    ActiveDrive drive = new ActiveDrive('z', new Uri("http://dav.webdavsystem.com"), "User1", "pwd");
    drive.Mount();

To unmount the drive call ActiveDrive.Unmount() method. Note that when an instance of ActiveDrive drive is destroyed the drive is unmounted from the file system.

If you would like your drive to be mounted each time computer boots usually you will have to create a Windows Service application. Alternatively you can add path to your application under the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
registry key. In this case, your application will run when user log-ins to the computer.

Core API Deployment

If you run 32-bit Windows, with your application you must deploy all files located in \x86\Core\ folder. For 64-bit Windows use files located in \SDK\x64\ folder.

Logging

IT Hit Map WebDAV Drive logs all requests and responses as well as exceptions to a log file. By default, the log file is created in the folder where your application resides. If you experience any problems with Core API examine the log file first.

Your application must have permissions to create, delete and move (rename) files in the folder where the log is being written. If you do not see the log file most likely there is not enough permissions for creating the file. To set the path to a log file add a reference to ITHit.WebDAV.Client.dll to your project, add using statement and set the FileLogger.LogFile static property:

 using ITHit.WebDAV.Client.Logger;

...

FileLogger.LogFile = "C:\MyWebDAVDrive.log";
FileLogger.Level = LogLevel.All;

See FileLogger class reference for more details.