Virtual Drive Sample in .NET, C#

In this article

Virtual Drive Sample in .NET, C#

This is a virtual drive implementation with thumbnail support, Microsoft Office documents editing support, and automatic Microsoft Office documents locking. It also demonstrates custom column support in Windows File Manager. 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 that is 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.

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 Core 3.1 or later.
  • 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 License field in appsettings.json file.

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 https://www.userfilesystem.com. 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. 

Packaging Project

This sample provides a Windows Application Packaging Project which allows deployment of your application to the Windows Store, simplifies COM components debugging (thumbnails handler and Windows Explorer context menu), as well as your application can be installed without admin privileges. The package can be also used for direct deployment to users.

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.

Now run the project from Visual Studio. This will automatically register COM components as well as you can start debugging COM components without additional steps.

Thumbnails Support

The Virtual Drive sample provides a separate project with thumbnail provider 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 this project to load thumbnails from your real remote storage.

The thumbnails provider is registered as an application extension by the packing project provided with the sample. To register thumbnails you will simply run the packaging project. You do NOT need to register the thumbnails handler using regsrv32 or any using any other COM registration technique.

 

Microsoft Office Editing Support

Another major difference between the Virtual Drive sample and the Virtual File System sample is its support for Microsoft Office Documents editing. This sample supports synchronization of the MS Office documents, avoiding the creation of the temporary files in the remote storage as well as it does not rename or delete the document in your remote storage during MS Office transactional save operation, preserving all data associated with a file in your remote storage.

This sample automatically locks the Microsoft Office document 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 to the document are being saved on the local drive, without being sent to the remote storage. You will see the not In-Sync icon  being displayed when you modify and save the document. The updated document content is sent to the remote storage when the document is closed, together with the lock-token and eTag. 

This sample provides classes for storing and managing lock information received from your remote storage and a code template for supplying the lock-token with each update operation, Windows File Manager icons updates, and Windows File Manager custom properties update. Locks, eTags, and custom properties are being stored in the application data folder, under the path that corresponds to the mounted virtual drive. The path to the data folder typically looks like: C:\Users\<user>\AppData\Local\Virtual Drive\C\Users\<user>\VirtualDrive\ServerData\

Any temporary Microsoft Office documents (~$docfile.docx, G57BURP.tmp, etc) are stored in the local file system only and are NOT synchronized to the server. Temporary Microsoft Office documents are being automatically deleted by Microsoft office when the document editing is completed.

Window File Manger Custom Columns Support

This sample registers and displays custom columns in Windows File Manager. For demo purposes the Registrar class add 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

 

Next Article:

WebDAV Drive Sample in .NET, C#