Editing MS Office documents from a web application: custom WebDaV implementation or ...?

Venkat picture Venkat · Jul 22, 2011 · Viewed 13.3k times · Source

Following is our setup & requirement:

  • There's a public web application accessible via SSL + Basic Authentication. Most of these applications are in ASP.Net; couple of legacy ones are in classic ASP. Server is Win 2003 / IIS 6.0
  • This application needs to support online editing of (mostly) MS Office documents (2007 & 2010). The documents themselves are stored in the database, along with the content of the application.
  • The users should be able to open the document via HTML links; the corresponding external Office application (say MS Word) should open the document in edit mode (with exclusive lock) and when the user presses Save button, the document should be posted back to the application.
  • Preferably no external plugins/ActiveX controls need to be deployed on the client side.

Is a custom WebDAV implementation the best possible approach? Note that we might not need all the features of WebDAV for supporting above requirements. Are you aware of any alternatives?

If custom WebDAV implementation is the way to go, can you please recommend some good resources (commercial/open source IIS plugins, samples in .Net, docs, etc), apart from http://www.webdav.org/ ? BTW, I do not prefer installing a bulky CMS like Sharepoint to support such a small requirement!

I found a thread on SO about custom WebDav implementation: What are your experiences implementing/using WebDAV? It sounds so discouraging :( (Avialable only on IIS root, requires Windows authentication, etc)

Thanks in advance!

Answer

Brendan Hannemann picture Brendan Hannemann · Jul 27, 2011

I recently developed a simple Webdav server using the Apache Tomcat WebdavServlet as a base. I just got the source from SVN (see below) and modified it to meet my needs. You can add code to the different methods in there:

doGet
doLock
doPut
doUnlock
etc...  

I am using it as a poor mans webdav in front of an enterprise CMS, so within each method I added API calls to fetch the document, lock it, version it, or whatever. Basically they didn't want to buy the webdav product from the vendor, and Tomcat is free.

As for opening the Office files on the client, you may need to rely on a library that ships with Office installs (since Office XP at least). Note that the component is called SharePoint blah blah but it does not require a SharePoint install anywhere. I have a js snippet here that uses the library for an example, obviously you would modify to meet your needs. I realize you said no ActiveX, but without it I am not 100% sure how you would open the links. You're welcome to try other ways.

function webedit(id) {
        if (window.ActiveXObject) {
            var ed; 
            try {
                //Office 2003
                ed = new ActiveXObject('SharePoint.OpenDocuments.2');
            } catch (err1) {
                try {
                    //Office 2000/XP
                    ed = new ActiveXObject('SharePoint.OpenDocuments.1');
                } catch (err2) {                
                    try {
                        //Office 2007
                        ed = new ActiveXObject('SharePoint.OpenDocuments.3');
                    } catch (err3) {                
                        window.alert('Unable to create an ActiveX object to open the document. This is most likely because of the security settings for your browser.');
                        return false;
                    }
                }
            }
            if (ed) {
                ed.EditDocument('<%=webdavPath%>/webdav/'+id);
                return false;
            } else {
                window.alert('Cannot instantiate the required ActiveX control to open the document. This is most likely because you do not have Office installed or you have an older version of Office.');
                return false;
            }
        } else {
            window.alert('Internet Explorer is required to use this feature.');
        }
        return false;    
    }

I also realize that your server is IIS and not Apache-based, but you can always front the Tomcat install with IIS (it's what we do) and use the JK ISAPI filter over AJP. Anyway, it's one way of doing things and doesn't require you to purchase anything.

SVN source: http://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/WebdavServlet.java