C# Webdav server with SQL Backend Source Code
The C# visual studio 2005 source code for this project is here
I finally got around to getting all of the source code for the webdav server I developed in C# with a SQL backend, I have talked a bit about this previously , but only now have had the time to but it all together so others can download and use/update the code.
The main reason I wrote this code was to provide a "network share" interface to some of my .net applications. I thought it would be very useful to have a framework in place where I could trigger some form of event when someone saved a word file or updated a speadsheet. Because all of the files are stored in a database under the control of the .net application creating this sort of thing is relatively trivial. I have used this to automatically process excel data into a database when someone saves a file to a particular folder for example. (You could also do this via e-mail using this, but that is a different idea). You could also use this to provide per-user content for a single file.
This server is purely for use with Windows Explorer and Microsoft office, so I have not implemented alot of the webdav stuff that isn't implemented by these products. ( this includes webdav-versioning , proppatch etc ), and I can't garauntee it will work with any other webdav clients. Basically this server implementation provides the minimal functionality required to allow MS office and Windows explorer to work.
I have implemented this project to provide 2 interfaces to the virtual filesystem ( provided by an sql database) . A standard web-front end and also the webdav interface. This means that if you connect to the server via a standard web browser you can view the virtual filesystem via a standard web page.
But if connect to the server via a webdav client connection then you get the webdav experience. Which allows you to create , edit, delete , copy , move , rename lock and unlock files and create, rename and delete folders.
There are a number of ways to get a connection to a webdav server as a network share. These include adding a "network place" from "my network places". The easiest way to get connected via webdav is to open the root url url for the application in IE and tick the "Open as web folder" option.
To setup the server you need to do the following steps and also I recommend visiting http://www.zorched.net/category/webdav/ for lots of helps on configuring webdav for .net
- Download the code and open in vs 2005 ( link at top of this post)
- Create a new blank database on your sql server
- run the create.sql code from the database project against the new database to create the required tables, stored procs and data to support the virtual filesystem
- Edit the web.config of the web application project (hojuwebdisk.web) and adjust the database connection string of the "webdav" connection to suit your environment.
As this is a webdav server you will also need to adjust the IIS setting for the website so that it knows how to handles the additional HTTP methods that webdav supports (LOCK, UNLOCK,PROPFIND,MKCOL etc ). Basically because we want .net to intercept all the calls (because we are redirecting all queries to our database not the filesystem) we need to adjust the application extension mapping so all extensions on all VERBs map to the asp IIS handler.
To do this you need to open the application properties of your website from the IIS console and then click the configure button. You then need to remove all of the application extensions and then create a new one for all extensions (.*) for all verbs that executes the .net isapi handler.
A good article explaining the ins-and-outs of this is available here
Once you have completed this setup you should be able to see the webdav server through a webdav connection, and therefore be able to add files and away you go..
I have to give credit to another project for helping me out with this one. The database and database interface stuff was all me, but a lot of the webdav implementation code I got from the webdav server project on sourceforge . If you are looking at developing your own webdav server or extending this code I totally recommend you check out that project. There project uses alot of events and delegates, where as I went with a single interface handler to simplify the code.
If you need any help, or want to add feedback then please do so. Microsoft office and windows have a number of wonderful webdav quirks, which you may need to get around depending on your environment and setup. A good place to start for a list of these is here
So good luck..