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..
53 Comments:
Great great great! Thank you very much for providing your code!
By Anonymous, at 4:52 pm, July 07, 2007
Hi,
I need some help.
When i'm trying to open as web folder, i get an error: "network path not found".
I 've tried another webDav Explorer, which can open the folder, but i couldn't do any operation in the folder.
Thanks,
Bob
By Anonymous, at 6:30 pm, July 25, 2007
Hi! Great work!
But it has a problem with some special characters in the filenames ('&' etc.). It seems, that aspnet_isapi.dll parses the URL in some way and so it is not possible to upload a file a&b.txt into this webdav server. Did anybody solved this problem?
By Anonymous, at 5:29 pm, July 26, 2007
Hi Honza,
I am not sure about all the special character you will need to look at the code and figure out how the application is re-mapping the characters in the the incoming url and xml information, to see if you can figure this out.
I do know that files with ampersands in them will not work because this creates a malformed url that IIS does not parse up to the aspnet_isapi.dll for processing. As it is not handled by aspnet_isapi.dll then it is completly unavailable to the application.
I haven't been able to find out how to fix then problem yet.
By Simon, at 3:57 pm, August 01, 2007
Hi,
Somebody, pleaseee help. It works fine with MS Word but i can't open it as a web folder from the explorer.
Thank's
Bob
By Anonymous, at 1:50 am, August 07, 2007
Hi,
Somebody, pleaseee help. It works fine with MS Word but i can't open it as a web folder from the explorer.
Thank's
Bob
By Anonymous, at 1:50 am, August 07, 2007
Hi Hoju Saram
it seems that only way to solve the problem with special character such as ampersand is to write an isapi filter, which decodes an URL before IIS passes the request to the aspnet_isapi.dll.
I have another question: what was your source for microsoft-specific properties,codes etc. which you used in your webdav server? Is there any part inside MSDN to find it? Or you just experimented with webfolder client?
Thank you in advance
By Anonymous, at 12:08 am, August 11, 2007
Anonymous,
The problem with the system not working in explorer but in word, may be related to how the OPTION methos is issued. Please see this page http://www.zorched.net/2006/03/01/more-webdav-tips-tricks-and-bugs/
By Simon, at 8:11 pm, August 13, 2007
WebDAV Server framework for .Net:
http://www.webdavsystem.com/server
It has several samples for MS SQL Server.
By Anonymous, at 11:52 pm, September 24, 2007
Windows 2000 Server, IIS 5, SQL Server 2000, VS 2005
running sql script fails
connecting to site fails
any idea or some workthrough document ?
By Anonymous, at 12:53 am, January 19, 2008
Hi, Hoju Saram.
I need some help.
When i'm trying to open as standart URL "http://localhost/HojuWebDisk", i get a HTML page "HojuWebDisk:/" with image "Folder with Earth".
When i'm trying to open as web folder, i get an error: "network path not found".
Please, help me!
By Anonymous, at 8:14 pm, February 14, 2008
If you are seeing the web-server via standard http GET. Then I suspect you webdav connection problem is the IIS server setup for the application. You need to make sure you have configured the virtual directory to accept all of the http verbs and that all of these verbs are handled by asp .net. Have another go at configuring the web site, and also check the IIS log to see what requests are being pasted to your application from windows explorer.
By Simon, at 9:02 pm, February 14, 2008
Thank you very mach!
I was reconfigured IIS and HojuWebDisk was opened!
Unfortunately, I Have another problem: http://localhost/HojuWebDisk as web-folder open ONLY on Windows 2003 Server Ent SR1! Other OS (such as WinXP and Win2000) give error "network path not found".
If I use the other WebDAV-client, that all right in the all OS!
Again error: Windows 2003 Server give error "syntactic error in file name. folder name or disk label" when I try open .txt file by double-click.
What is the matter?
p.s. Sorry about my english :)
By Anonymous, at 6:02 pm, February 15, 2008
I solved this problem!!!
The solution is here http://ulihansen.kicks-ass.net/aero/webdav/
By Anonymous, at 12:24 am, February 22, 2008
Hello
Great work, but i have a question:
I can see the foldercontents via GET in Internet Explorer, but i canĀ“t map the WebDAV Folder from Windows Explorer.
I followed chiefs link, but none of the solutions worked for me!
Can anyone please help me?
By Anonymous, at 6:48 pm, April 15, 2008
Although it works fine with Windows Explorer, as a Web Folder and also with office apps. But I cannot map a logical drive to the network share I created for my WebDAV site. Is there any issue for this....
By Anonymous, at 7:24 pm, May 21, 2008
i need some help
i download and i am try to run this in vs2008 but its giving error
you r not authorised to view this page. in sql server also the create.sql is not working its giving so many error please give some solution to me please give the detail steps to me
By goms, at 5:21 pm, July 14, 2008
Hi,
when i try to run this in vs2008 windows xp
but its giving error unable to start debugging on the web server the webserver could not fing the requested resource is coming i don't know how to solve this please help me its very urgent
By Anonymous, at 6:57 pm, July 14, 2008
when i am trying to open this http://localhost/HojuWebDsik
its giving error you are not authorised to see this page
By Anonymous, at 7:04 pm, July 14, 2008
hello hoju saram
when i am try to give the link
http://localhost/HojuWebDisk
its giving network path not found id coming
i configured the iis also
then also its coming
when i try to run this using the below path
http;//localhost/HojuWebDisk/folder.aspx?FPath=&_MWDRes
its giving error
object reference not set to an instance of the object error is coming please help me
how to run this application
By Anonymous, at 5:40 pm, July 15, 2008
The authorization error can be solved by adding
<remove name="FileAuthorization" />
to the web.config under system.web/httpModules (& maybe system.webServer/modules)
Still having problems getting this to work (under Vista/IIS7). Had to set the site to use Classic App pool (tried to migrate config to integrated but failed).
Now also cannot connect using File/Open as Web Folder in IE.
Might be problem with Class 2 (locking) support. Also see ITHit site (http://www.webdavsystem.com/server/documentation/getting_started).
Anyone?
By Anonymous, at 6:56 pm, July 29, 2008
Finally got this working (under Vista)! Used DAVExplorer (http://www.davexplorer.org/) which is a Class 1 complient client.
Also saw a 405 error on a PROPFIND on the root in the IIS log when using IE File/Open as Web Folder or Notepad, so placing the app in the root of a new web site might solve this. Maybe more later...
I did encounter a problem with images not being displayed correctly in the website which i resolved by adding a StaticFileModule for each ext.
Anyway, great work Hoju! 3 cheers 4 u!
By Anonymous, at 10:44 pm, July 29, 2008
Moved it to it's own website, 405 err became 207 Multistatus (is ok), but still can't access it from Office (2007), Notepad or as Web Folder (all under Vista).
Also can't do a GET on the root (so use /Folder.aspx?...etc) (minor) and can't get to images to work in the website (cosmetic).
Still works with DAVExplorer though.
Now i'll determine if we should use this or the ITHit component (pro/pay) for our company.
Bye!
By Anonymous, at 11:48 pm, July 29, 2008
Hi all,
Sorry but I can't offer much support for this. This is a project I worked on some time ago and I know have other things that I have moved onto that take up my time.
I can however say that most of the problem that are being experienced are due to microsoft implementation on webdav at the client. You most definitely should read and try to understand everything here
http://www.zorched.net/category/webdav/
The main problem people have is that MS office will always send the OPTIONS verb to the root of your website. So you must either setup the application on its own virtual server (IIS 6.0) or somehow implement OPTIONS at the root of your webserver.
If you are having trouble with connectivity I would recommend downloading wireshark
http://www.wireshark.org/
and doing some protocal analysis between the client and the IIS Server ( although this will require two seperate machines as wireshark can't handle loopback capture on windows).
And finally, really the microsoft implementation of webdav protocol is plain stuffed.
From a commercial perspective you can see why they did it, because if they implemented it properly no one would ever buy sharepoint.
So having said that if someone has the time to write a proper client that is user friendly that would be great. I started looking into this ( using a custom protocol as I really consider webdav to heavy )
http://thehojusaram.blogspot.com/2008/06/my-webdisk-client.html
but as I said before I have no time at the moment.
Thanks for all your kind words and glad I could contribute.
By Simon, at 11:10 pm, July 30, 2008
I've spent some time getting to the bottom of this and i've found that the Microsoft Client doesn't like the XML produced.
To at least get Web Folder past the errors and display something you need to
1. Add a trailing Z to creationdate for files & folders
2. Implement depth on PROPFIND (0 = only the folder itself, 1 = folder + children)
I've used the book "Next-Generation Collaborative Web Authoring" by Lisa Dusseault as a reference and compared the XML to the XML produced by the ITHit Server component.
Other errors
3. Correct propertynames
getlastmodified
getcontent*
4. PUT doesn't work for me yet
Maybe i'll look in to this later.
However this still is a good place to start building your WebDav Server.
By Anonymous, at 10:12 pm, August 01, 2008
I forgot an important one:
5. hrefs need to be a abs full path ending with a /. Example: http://hojuwebdisk/testfolder/
Hope this is helpful for some of u.
By Anonymous, at 11:54 pm, August 01, 2008
Fixed PUT/LOCK too:
1. Comment out the "if getRequestLength() == 0" in PUT_Handler.Handle to be able to create empty files.
2. Add the D namespace prefix in the WriteStartElement for prop:("D", "prop", "DAV:");
My Web Folders (Vista) seems to require this.
Some fixes i came accross when reading about the protocol (not required for Web Folders):
3. Add response headers for the Lock-Token and Content-Type at the beginning of LOCK_Handler.BuildResponse
4. Set this._LockDepth = DepthType.ResourceOnly (0) when a file is requested. This is the only meaningful value for files.
CU,
KD
By Anonymous, at 11:22 pm, August 04, 2008
I forgot to mention the location for fix 2 of the previous post: At the start of LOCK_Handler.BuildResponse.
More fixes (for Vista/Office 2007)
1. GET_Handler: add
if (_fileInfo.FileData.Length > 0)
before
_outputStream.Write(_fileInfo.FileData);
to make it possible to GET/open an empty file in f.e. Notepad & Word 2007.
2. Implement a stub PROPPATCH Handler that returns an empty 207 Multistatus response to allow Word 2007 to save & Web Folders to Copy (bypass errors).
3. add if (urlPath == "") return null; to start of WebDavHelper.getFile so it doesn't crash on GET / (maybe later i'll work on getting the web frontend running completely properly in the root)
KD
By Anonymous, at 7:40 pm, August 05, 2008
Ok, got web frontend also running properly in site root. This fixes the problems described in my post from 11:48 PM, July 29, 2008.
Fixes:
1. Redirect in GET_Handler. Use part of Request.Url.AbsoluteUri instead of Request.ApplicationPath
2. Images not showing (401.3)
This can be solved in 2 ways:
a) Grant IUSR ntfs rights on the physical wwwroot folder
b) Set the anonymous auth account to "app pool identity". IIS7: Dclick Auth icon, select Anon. Auth., on the right under actions select Edit...
Hope this helps.
KD
By Anonymous, at 11:26 pm, August 05, 2008
hi KD
i am using hojuwebdisk its creating webfolder
in that when i am copying files from one folder to another folder that time its giving error
file already existing
but file is not already existing
one more is when i am doing refresh in webfolder that time no contents in the webfolder
its empty move also giving unable to move error
please give idea to solve this problem
By Anonymous, at 10:19 pm, August 21, 2008
Thanks from Russia
By Unknown, at 5:29 pm, September 05, 2008
Hi,
@andrey: You're welcome!
@Anonymous, at 10:19 PM, August 21, 2008:
Unfortunately I don't have any time to dig deeper into this (because our company purchased the ITHit component). For your first problem I would debug the appropriate (PUT_, COPY_ or MOVE_) Handler.cs.
Your second problem sounds like clientside caching to me. I have had lots op problems when an error occurs the cache isn't flushed/updated, so it looks like a file is copied/modified when it really isn't. So always look at your backend storage (DB or FS) to be sure.
Good luck!
By Anonymous, at 7:28 pm, September 11, 2008
I was trying to test your project but it tells me
Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=50eb4a5cd9a4cf03' or one of its dependencies. The system cannot find the file specified.
where do I get this assembly?
By Anonymous, at 6:52 pm, December 08, 2008
Hi for all!
I got a problem in IIS 6 on MS Windows Server 2003:
I can't map all extensions by (.*) - it gets the error message:
"Wrong extension format"
Anybody knows how to solve this?
By Anonymous, at 10:18 pm, January 15, 2009
Very nice, just what I was looking for.
By Anonymous, at 4:43 am, February 26, 2009
Dear Sir,
I have a launched new web site for .NET programming resources. www.codegain.com. I would like to invite to the codegain.com as author and supporter. I hope you will joins with us soon.
Thank You
RRaveen
Founder www.codegain.com
By RRave, at 9:30 pm, June 07, 2009
Hi, did you implemented CalDav with your WebDav-Code?
Best regards
Christoph
By Christoph Schmid, at 4:05 am, April 26, 2011
Hi all,
I've got some problem in IIS 7 on Window 7. I need some help.
I can view vitual filesystem via a standard wed page but i can't map files and folders on window explorer.
IF I removed all of the application extensions and then create a new one for all extensions (*) for all verbs that executes the .net isapi handler. BUT I can't see My Network drive.
Best requards
QuyenNB
By QuyenNB, at 6:49 pm, June 23, 2011
I am currently trying to get this code working on Windows 7 with ASP.NET and IIS7.5. I also plan on getting extending it to also support off site storage (Amazon S3 or similar) with background backup... I have taken a "fork" of the code and placed it on GitHub at https://github.com/tiernano/HojuWebDisk If you are interested. The code was updated to VS2010, and i am making tweaks as i go... Any comments, questions or problems with this, please let me know. Thanks.
By Lotas, at 3:51 am, September 01, 2011
I setup your new code successful.But when I edit and save a docx file.I can't update it to database.I always see file "Locked by another user".Can you please help me about the issue.
Many thanks.
By Anonymous, at 6:12 pm, December 05, 2011
Do you care if we use your webdav implementation posted here in a commercial application? You have a nice stripped down version of what we need and I would like to use it. Thanks.
By Anonymous, at 10:59 am, August 14, 2012
can we browse in windows explorer without using any web dav client???
By Anonymous, at 2:36 am, March 13, 2013
can we browse in windows explorer without using any web dav client???
By Anonymous, at 2:36 am, March 13, 2013
This comment has been removed by the author.
By Unknown, at 7:36 am, April 03, 2013
Yes, you can browse without installing WebDAV client. In fact Microsoft Windows provides built-in client, called Mini-redirector. Here is how to use it: http://www.webdavsystem.com/server/access/windows/miniredirector
You can also open files directly from web page, see the demo here: http://ajaxbrowser.com
By Anonymous, at 7:38 am, April 03, 2013
Hi,
I'm trying to configure HojuWebDisk but when I use windows explorer to create a folder it doesnt create in the database. I can view the tree folders in Folder.aspx so I can conect to the database.
I think that the problem is in iis7 config.
Anybody know how to config iis7 to try HojuWebDisk?
Thanks
By Anonymous, at 8:39 pm, April 11, 2013
I can't conect with windows explorer.
Is it necesary to do basic or digest authentication? How can I do it?
I would like to use only windows authentication.
Thanks.
By Anonymous, at 8:16 pm, April 17, 2013
Awesome work! Thanks very much.
Still a hip feature in business apps!
By Unknown, at 5:57 pm, October 31, 2014
This comment has been removed by the author.
By Unknown, at 6:27 pm, February 20, 2015
Hello,
I'm looking for that kind of example... is it still available?
where can I download the solution?
is this solution compatible with a newer version of visual studio ?
thanks
Tibo
By Unknown, at 3:48 pm, July 07, 2015
+1
By Michael, at 7:02 pm, October 22, 2015
+1. the download link is dead :/
By Unknown, at 2:08 am, December 14, 2017
Does anyone know where I can get this source code from?
By Unknown, at 9:50 pm, July 31, 2018
Post a Comment
<< Home