ASP.NET WebDAV Server Example with Microsoft SQL Back-end, C#
This is a legacy sample provided with IT Hit WebDAV Server Engine v4.5 and earlier based on HttpHandler. An article about a new cross-platform SQL Storage sample running on ASP.NET Core, provided with IT Hit WebDAV Server Engine v5 can be found here.
Here we will describe how to install and configure WebDAVServer.SqlStorage C# example provided with SDK, that demonstrates how you can build a WebDAV Server with SQL back-end. This example is a Class 2 WebDAV server that runs in ASP.NET on IIS or IIS Express and stores all data including locks, file content and custom properties in Microsoft SQL Server database. The WebDAVServer.SqlStorage example is a fully-functional WebDAV server that can be used to open, edit and save Microsoft Office documents directly on a server, without download/upload steps. You can use it to access documents using Microsoft Mini-Redirector/Web Folders, Mac OS X Finder or any other WebDAV client.
To run this example, you will need:
ASP.NET 4.5 or later on Windows Server 2012, Windows Server 2008, Windows 10, Windows 8, Windows 7 or Windows Vista.
Microsoft SQL Server Express LocalDB or Microsoft SQL Express or Microsoft SQL Server 2014 / 2012 / 2008 / 2005.
For simplicity of evaluation Visual Studio 2012 or later are recommended. This sample does not support Visual Studio 2010.
Important! Because this sample uses TAP interfaces you need .NET 4.5 or later to run it. If you need to support .NET 4.0 or 3.5 use the 'ASP.NET CalDAV/CardDAV Server Application' wizard or other WebDAV wizards in Visual Studio and select .NET 4.0 or .NET 3.5 in a New Project dialog.
Installation and Configuration
By default WebDAVServer.SqlStorage example is installed to C:\Users\<UserName>\Documents\IT Hit\WebDAV Server Engine\vX.X.X\Samples\WebDAVServer.SqlStorage\ folder.
Setting the License
To run the example, you will need a valid IT Hit WebDAV Server Engine License. You can download the license here. 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.
Place the license file in the root folder of the WebDAVServer.SqlStorage Example (\Samples\WebDAVServer.SqlStorage\).
Running Example from Visual Studio
If you have Visual Studio with Microsoft SQL LocalDB installed, the simplest way to run the sample is to run it from Visual Studio. In this case, you do not need to configure the web application in IIS and create MS SQL Database.
Note that in case you are using Visual Studio 2010, SP 1 and IIS Express are highly recommended. After opening the project in Visual Studio 2010 switch to IIS Express using ‘Use IIS Express’ project menu.
Configuring the Database
In case you have Microsoft SQL LocalDB installed and are running the sample from Visual Studio you do not need to configure the database. In this case your database file, WebDav.mdf, is located in \Samples\WebDAVServer.SqlStorage\App_Data\WebDav\DB\ and will be automatically attached when you run the sample from VS, see below:
If you have Microsoft SQL Express installed you need to update the connection string. The connection string for Microsoft SQL Express is provided in a web.config file.
If you do not have Microsoft SQL Express or LocalDB installed or running your sample in IIS you will need to create and configure the database. The database script, DB.sql is located in \Samples\WebDAVServer.SqlStorage\ folder. In most case, you will open the Microsoft SQL Server console and execute this script. The script will create the database with a name ‘WebDav’ and all required tables. It will also create several folders and files. Finally update the connection string in the web.config file to access your new database.
The Project Classes
On the diagram below you can see the classes in WebDAVServer.SqlStorage project.
To adapt the sample to your needs, you will modify these classes to read and write data from and into your storage. You can find more about this in Creating a Class 1 WebDAV Server and Creating Class 2 WebDAV Server article as well as in the class reference documentation.
How Things Get Stored – Overview of the SQL Back-end
The database consists of 3 entities as depicted in the figure below.
All the information about files and folders along with their content is stored here. Following is the list of columns with a brief description of each field.
The Lock table stores lock applied to items. You can find more about locking in the Creating Class 2 WebDAV Server article.
All the information about the properties pertaining to each item is stored in Property table.