Virtual Drive Sample for Windows in .NET, C#

This is a virtual drive implementation for Windows with thumbnail support, custom context menu and custom states & columns support. It also demonstrates automatic Microsoft Office/AutoCAD documents locking. 

To simulate the remote storage, this sample is using a folder in the local file system on the same machine. This sample supports all basic synchronization features provided by the Virtual File System sample: folders on-demand listing, files on-demand content loading, selective offline files support, hydration progress. The sample is written in C#/.NET.

This sample supports application identity (sparce package) and provides a packaging project for deployment to Windows store.

You can download this sample and a trial license in the product download area as well as you can clone it from GitHub

This sample is provided with IT Hit User File System v3 Beta and later versions.

  • .NET 6 or later or .NET Framework 4.8.
  • Microsoft Windows 10 Creators Update or later version.
  • NTFS file system.

By default, the sample will use the \RemoteStorage\ folder, located under the project root, to simulate the remote storage file structure. It will mount the user file system under the %USERPROFILE%\VFS\ folder (typically C:\Users\<username>\VirtualDrive\).

To specify the folder that will be used for remote storage simulation edit the "RemoteStorageRootPath" parameter in appsettings.json. This could be either an absolute path or a path relative to the application root.

To specify the user file system folder edit the "UserFileSystemRootPath" parameter in appsettings.json.

To run the example, you will need a valid IT Hit User File System Engine for .NET License. You can download the license in the product download area. Note that the Engine is fully functional with a trial license and does not have any limitations. The trial license is valid for one month and the engine will stop working after this. You can check the expiration date inside the license file. Download the license file and specify its content in the UserFileSystemLicense field in appsettings.json file. Set the license content directly as a value (NOT as a path to the license file). Do not forget to escape quotes: \":

"UserFileSystemLicense": "<?xml version=\"1.0\" encoding=\"utf-8\"?><License…

You can also run the sample without explicitly specifying a license for 5 days. In this case, the Engine will automatically request the trial license from the IT Hit website Make sure it is accessible via firewalls if any. After 5 days the Engine will stop working. To extend the trial period you will need to download a license in a product download area and specify it in appsettings.json

To run the sample open the project in Visual Studio and run the project in debug mode. When starting in the debug mode, it will automatically create a folder in which the virtual file system will reside, register the virtual drive with the platform and then open two instances of Windows File Manager, one of which will show a virtual drive and another a folder simulating remote storage. 

You can find more about running and stopping the sample as well as about basic synchronization features in the Virtual File System sample description. 

Shell Extensions Support

This sample provides thumbnails handler, context menu handler and custom states and properties handler. All handlers are registered as an application extension by the packing project provided with the sample or as a sparse package manifest of the main application. To register handlers you will simply run either VirtualDrive project directly or the VirtualDrive.Package project. You do NOT need to register the handlers using regsrv32 or any using any other COM registration technique.

The COM handlers are automatically unregistered on package uninstall, you do not need to unregister them manually.

Thumbnails Support

The Virtual Drive sample provides thumbnail provider shell extension implementation in the COM object. It loads thumbnails from files located in the remote storage simulation folder and displays them in Windows Explorer. You will adapt the code to load thumbnails from your real remote storage.

Virtual Drive thumbnails support in Windows Explorer

Context Menu Support

This sample provides a context menu provider that implements manual locking and unlocking:

Virtual drive context menu handler provider

Note that context menu support on Window 11 requires application or package identity. The sample is provided with a test developer certificate for this purpose. You must replace the certificate with your own certificate prior to deployment.

See more details on on implementing and registering context menu in the Creating Custom Windows Explorer Context Menu Shell Extension article.

Window File Manger Custom States & Columns Support

This sample registers and displays custom states & columns in Windows File Manager. For demo purposes the Registrar class adds ETag column as well as columns that show information about the lock: Lock Owner, Lock Scope, Lock Expires:

  Virtual Drive custom columns being displayed in Windows File Manger

See more information about how to program and register the custom states and columns handler in Creating Custom States and Columns Provider Shell Extension for Virtual Drive article.

Automatic Locking of Microsoft Office and AutoCAD Files

This sample automatically locks the Microsoft Office and AutoCAD documents in the remote storage when a document is being opened for editing and automatically unlocks the document when the file is closed. When the document is opened you will see the lock icon Lock icon in the Status column in Windows File Manager:

Virtual Drive sample shows lock icon for Microsoft Office documents

The information about the lock (lock-token, etc.) is being saved on the client machine when the document is locked. When a document is modified on the client, all changes are sent to the remote storage, together with the lock-token and eTag. 

You can find more more about locking programming in this section

Packaging Project

Starting with IT Hit User File System v5 Beta, the VirtualDrive project supports identity and provides the same functionality as VirtualDrive.Packaging project. Starting VirtualDrive project directly registers thumbnails handler shell extension, context menu handler and custom states & columns handler.

This sample provides a Windows Application Packaging Project which allows deployment of your application to the Windows Store. The package can be also used for direct deployment to users in a corporate environment or consumer environment. Start reading about various deployment scenarios in this article.

To start the project with thumbnails and context menu support follow these steps:

  1. Set the packaging project as your startup project.
  2. Set the VirtualDrive project under the packaging project as an Entry Point.

Run the project from Visual Studio. This will automatically register COM components.

The packaging project will perform an automatic cleanup on uninstall. Your sync root registration will be automatically unregistered, folders created by the application will be deleted as well as all COM components unregistered. 

See also:


Next Article:

WebDAV Drive Sample for Windows in .NET, C#