WebDAV Server Examples, C#

The IT Hit WebDAV Server Engine is shipped with sample WebDAV Servers implementations that could be used as a starting point for understanding WebDAV server engine.

SampleFeaturesHostingStorageMax File SizeAuthenticationCodeRemarks
Class1Listener Class 1 HttpListener MS SQL 2000/2005/2008 or MS Access 2Gb NTLM C# Does not support MS Office and Web Folders on 7/Vista
SQLStorage Class 2 IIS 5.0 or later MS SQL 2000/2005/2008 2Gb NTLM, Kerberos, Basic C#  
NtfsStorage Class 2, Resumable Upload IIS 5.0 or later NTFS file system Unlimited NTLM, Kerberos C#  
DeltaV Class 2, DeltaV, Resumable Upload HttpListener MS SQL 2000/2005/2008 and file system Unlimited NTLM, Kerberos, Basic, Digest #  

Class1Listener Sample

Class1Listener sample provides Class 1 WebDAV Server implementation based on HttpListener. For the sake of simplicity this sample was designed as a console application, can process only 1 request at a time and requires minimum configuration. No IIS is required to run this server. Microsoft SQL Server or Microsoft Access could be used to store data. This sample does not support Microsoft Office applications and Web Folders on Windows Vista. The project is a Visual Studio 2005 / 2008 / 2010 Console Application, C# source codes.

Server Requirements:

.NET Framework 2.0 or later on Windows Server 2008, Windows Server 2003, Windows 7, Windows Vista or Windows XP SP2
Microsoft SQL Server 2000 / 2005 /2008 or Microsoft Access.

Running the Sample

  1. Place License.lic file in the folder where the compiled exe file resides (\bin).
  2. Create the database. You can use one of two sample databases located in '\Samples\Class1Listener\DB' folder: MSAccessSample.mdb is a Microsoft Access database, MSSQLSample.sql is a script that creates and initializes the Microsoft SQL Server database. Both databases initially contain several hierarchy items. Edit Class1Listener.Listener.exe.config file located in '\bin' folder and change the connection string to the database.
  3. Change ListenerPrefix value. Specify url to which your server will be listening.

Finally run the exe file and connect to server with a WebDAV client that supports Class 1 servers. Note that on Windows Vista you must select Run as Administrator from context menu. If you experience any problems with connecting to the server examine the WebDAVLog.txt created in \bin folder. If you do not see the log file the requests do not reach the server.

SQLStorage Sample

SQLStorage sample provides Class 2 WebDAV Server implementation. The server runs as ASP.NET web application in IIS. This sample uses Microsoft SQL Server database to store data and utilizes Microsoft SQL Server particular features. For WebDAV Class 2 support ILock, IFolderLock and INullLock interfaces are implemented. Due to Class 2 support Microsoft Office applications and Windows Vista Web Folders could save files directly into WebDAV Server storage. This sample also utilizes transactions. The project is a Visual Studio 2005 / 2008 / 2010 Class Library project, C# source codes.

Server Requirements:

ASP.NET 2.0 or ASP.NET 4.0 on Windows Server 2008, Windows Server 2003, Windows 7, Windows Vista, Windows XP or Windows 2000 Server,
Microsoft Data Access Components(MDAC) version 2.6 or later,
Microsoft SQL Server 2000 / 2005 / 2008.

Running the Sample

  1. Place License.lic file in the root folder of your WebDAV server (\Samples\SqlStorage).
  2. Create the database. The database script located in \Samples\SqlStorage\DB folder. MSSQLSample.sql creates and initializes the Microsoft SQL Server database. The script initially creates several folder items. Edit web.config file located in \Samples\SqlStorage and change the connection string to the database.
  3. Create web application in IIS that will be the root of your WebDAV server storage. Configure your web application to catch all WebDAV related verbs. If you plan to use Microsoft Web Folders as your WebDAV client we recommend dedicating the entire website to your WebDAV server (map you WebDAV server to the root of the website). Read Configuring IIS.

Now connect to the server with a WebDAV client. If you experience any problems with connecting to the server examine the WebDAVLog.txt created in \SqlStorage folder. If you do not see the log file the requests do not reach the server or there are not enough permissions for crating the logfile.

NtfsStorage Sample

NtfsStorage is a Class 2 WebDAV server that supports Resumable upload feature. All data is stored in NTFS Alternate Data Streams, so this sample does not require any database and provides high performance. Even though this sample is hosted in IIS you can upload files over 2Gb using PUT with Content-Range header. To pause, cancel and restore broken uploads, you can use Sample WebDAV Browser provided with IT Hit WebDAV Client API. The project is a Visual Studio 2005 / 2008 / 2010 Class Library project, C# source codes.

Server Requirements:

ASP.NET 2.0 or ASP.NET 4.0 on Windows Server 2008, Windows Server 2003, Windows 7, Windows Vista, Windows XP or Windows 2000 Server,
NTFS File System.

Running the Sample

  1. Place License.lic file in the root folder of your WebDAV server (\Samples\NtfsStorage).
  2. Edit RepositoryPath value in web.config file located in \Samples\NtfsStorage folder and change the path to the folder where files will be stored.
  3. Create a web application in IIS that will be the root of your WebDAV server storage. Configure your web application to catch all WebDAV related verbs. If you plan to use Microsoft Web Folders as your WebDAV client we recommend dedicating the entire website to your WebDAV server (map you WebDAV server to the root of the website). Read Configuring IIS.
  4. Make sure your web application has enough permissions in your storage folder. To create, update and lock files and folders, ASPNET account (IIS 5.1) or NETWORK SERVICE account (IIS 6 or IIS 7) must have full control over this folder.

Now connect to the server with a WebDAV client. If you experience any problems with connecting to the server examine the WebDAVLog.txt created in \NtfsStorage folder. If you do not see the log file the requests do not reach the server or there are not enough permissions for crating the logfile.

DeltaV Sample

This sample is Class 2 and DeltaV compliant WebDAV server. It supports resumable upload so you can pause, cancel and restore broken uploads if you use WebDAV client that supports resumable upload, such as Sample WebDAV Browser provided with IT Hit WebDAV Client API. The server sample is based on HttpListener and can run either as a stand-alone exe or as Windows Service. For best performance documents are stored in file system while structure and custom properties are stored in Microsoft SQL Server database. This sample does not have any limitations on maximum file size. The sample supports Basic, Digest, NTLM and Kerberos authentication easily configured in application configuration file. It also demonstrates execution of all methods of interfaces implementation in a single transaction started at the beginning of each request and committed or rolled back at the end. C# source codes.

Server Requirements:

.NET Framework 2.0 on Windows Server 2008, Windows Server 2003, Windows 7, Windows Vista or Windows XP SP2
Microsoft Data Access Components(MDAC) version 2.6 or later,
Microsoft SQL Server 2000 / 2005 / 2008.

Running the Sample

  1. Place License.lic file in the folder where the compiled exe file resides (\bin).
  2. Create the database. The database script located in \Samples\DeltaV\DB folder. DeltaV.sql creates and initializes the Microsoft SQL Server database. The script initially creates several folder items. Edit WebDAVServer.DeltaV.exe.config file located in '\bin' folder. Change the connection string to the database.
  3. Edit RepositoryPath value in WebDAVServer.DeltaV.exe.config file located in '\bin' folder and change the path to the folder where files will be stored.
  4. Edit CustomHandlerPage value. Specify the path to MyCustomHandlerPage.html
  5. Finally you can either run the .exe or register the service.
    • If you run the .exe file note that on Windows 7, Vista or Server 2008 you must select Run as Administrator from context menu.
    • To register the service run running 'installutil.exe WebDAVServer.DeltaV.exe' in a command prompt. Open Services snap-in and run the DeltaVService service.

Now connect to the server with a WebDAV client. If you experience any problems with connecting to the server examine the WebDAVLog.txt created in \bin folder. If you do not see the log file the requests do not reach the server.

See Also: