Opening Documents for Editing From a Web Page

Important! This is a legacy article about IT Hit WebDAV Ajax Library v1. Java applets and any other NPAPI pugins, including plug-ins installed by MS Office 2010- are not supported any more. For information about IT Hit WebDAV Ajax Library v2 read this article. For information about how to upgrade your JavaScript API read this article.

Ajax WebDAV Library provides API for opening documents for editing directly from the server and saving back to the server without download and upload steps. This includes editing Microsoft Office documents, as well as any other file types and works on Windows, Mac OS X and Linux.

Preparing the Document Editing in MS Office

Microsoft Office 2010 and earlier versions, require the user to confirm Microsoft Office document opening from web: 

Click Run this time or Always run on this site in Google Chrome

To display the above confirmation bar call the ShowMicrosoftOfficeWarning() method.

In case this method is not called before opening a Microsoft Office document with Microsoft Office 2010 and earlier installed, the document will not open first time, user will need to call the document edit API again after confirmation.

While calling this method for Microsoft Office 2013 is not required, you can always safely call it. This call will be ignored, in this case.

Opening Document for Editing

To open the document for editing call the EditDocument() method passing document URL as a parameter and optionally Java Applet URL:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="ITHitWebDAVClient.js" ></script>
</head>
<!-- 
   ShowMicrosoftOfficeWarning will display MS Office warning if required when page is loaded. 
    Otherwise, MS Office documents do not open first time in case of MS Office 2010 and earlier. 
-->
<body onload="ITHit.WebDAV.Client.DocManager.ShowMicrosoftOfficeWarning();">
    <script type="text/javascript">
        function edit() {
            ITHit.WebDAV.Client.DocManager.EditDocument("http://server/folder/file.docx", "/ITHitMountOpenDocument.jar");
        }

    </script>
    <input type="button" value="Edit Document" onclick="edit()" />
</body>
</html>

Note that document URL always must be a full path including the domain name.

The EditDocument() call chooses a best available method for opening this type of document depending on file type, MS Office version (if detected) and OS. It works both with MS Office Files as well as any other types of files on Windows, Mac OS X and Linux. 

The EditDocument() call is using various approaches depending on the environment:

  • In case MS Office is detected, the Ajax WebDAV Library is using the web browser Add-in, Active X or protocol handler installed by MS Office to open Microsoft Office documents for editing. This is the fastest way to open documents and preferred to other types. This approach is available both on Windows and on Mac OS X. In the case of Mac OS X Microsoft Office 2011 for Mac is required.
  • In the case, MS Office is not installed or this is non-Microsoft Office document, the Ajax WebDAV Library is using Java Applet. This approach is available on Windows, Mac OS X and Linux.

Below you can see what method is used with each Microsoft Office version and web browser combination:

 IEChromeFirefoxSafari
Microsoft Office 2013 Protocol ext Protocol ext Protocol ext  
Microsoft Office 2011 on OS X   Not supported1 Add-on       Plugin     
Microsoft Office 2010 ActiveX Plugin2 Add-on  
Microsoft Office 2007 and earlier ActiveX Java applet2 Java applet  

 

Below you can see what method is used for each file type and web browser combination:

 IEChromeFirefoxSafari
MS Office documents Depends on MS Office version, see table above
Non-MS Office docs on Windows Java applet  Java applet2 Java applet  
Non-MS Office docs on OS X   Not supported1 Java applet Java applet
with elevated
permissions
Any files on Linux   Java applet2  Java applet  

 

1 Google Chrome on OS X is available as a 32-bit application only. It does not support neither Java 7 nor web browser plugins or protocol extensions. One solution for downgrading to Java 6 and enabling Java in Chrome could be found here: http://support.apple.com/kb/HT5559

2 In Google Chrome v42 Java, MS Office 2010 plugin and other NPAPI plugins are disabled. See how to enable NPAPI here: https://java.com/en/download/faq/chrome.xml#npapichrome

Protocol extensions, Plugin, Add-on and ActiveX are installed by Microsoft Office.

Customizing Open Document Editing

In case you wish to avoid using Java Applet, you can use MicrosoftOfficeEditDocument() method call. This method is using the web browser plugins, ActiveX and protocol extensions installed by Microsoft Office. To detect if Microsoft Office is installed use IsMicrosoftOfficeAvailable() method. To find out if this type of document is a MS Office document call IsMicrosoftOfficeDocument() method:

var sDocumentUrl = "http://server/path/file.docx"; // this must be full path
var oNs = ITHit.WebDAV.Client.DocManager;
if (oNs.IsMicrosoftOfficeAvailable() && oNs.IsMicrosoftOfficeDocument(sDocumentUrl)) {
    oNs.MicrosoftOfficeEditDocument(sDocumentUrl);            
} else {
    oNs.JavaEditDocument(sDocumentUrl, null, "/plugins/ITHitMountOpenDocument.jar");
} 

The MicrosoftOfficeEditDocument() can open for editing the following file types: 

  • Microsoft Word documents: docx, doc, docm, dot, dotm, dotx
  • Microsoft Excel documents: xltx, xltm, xlt, xlsx, xlsm, xlsb, xls, xll, xlam, xla
  • Microsoft PowerPoint documents: pptx, pptm, ppt, ppsx, ppsm, pps, ppam, ppa, potx, potm, pot
  • Microsoft Access documents: accdb, mdb
  • Microsoft InfoPath documents: xsn, xsf
  • Microsoft Publisher documents: pub
  • Microsoft Visio files: vstx, vstm, vst, vssx, vssm, vssm, vss, vsl, vsdx, vsdm, vsd, vdw,
  • Microsoft Project files: mpp
  • OpenOffice Writer: odt
  • OpenOffice Calc: ods
  • OpenOffice Impress: odp

For all other types of documents, the Java Applet should be used.

Server Requirements for Microsoft Office Documents Editing

  1. Your WebDAV Server must support Class 2. Microsoft Office will lock the item that is being opened for editing.
  2. In the case of Microsoft Office 2007 and earlier your WebDAV server must be available on the site root, it must process OPTIONS and PROPFIND requests.
  3. In case, your server is using Basic authentication your server must be accessed via HTTPS/SSL (at least with self-signed certificate).

Using the Java Applet

Important! Since Google Chrome v42 all NPAPI plugins, including Java applets are disabled by default. See how to enable Java in Chrome here: https://java.com/en/download/faq/chrome.xml#npapichrome

In case you prefer using the Java applet, call JavaEditDocument() method.
The JavaEditDocument() method is doing the following:

  1. Mounts WebDAV folder provided in a second parameter in your local file system. It will present the login dialog if required. The logic of the login dialog is different for every OS. On Windows and Mac OS X the OS-powered login will be displayed while on Linux the Java applet will present its own Java login dialog.
  2. Executes default OS file open command.

The JavaEditDocument() accepts following parameters:

  • Document Url. Url of the file to be opened. This must be a full path including the domain name.
  • Url to be mounted. URL of the folder that will be mounted on your local file system. Usually, this is your WebDAV server root. In some cases, your WebDAV server root is not the same as your website root (for example your WebDAV may be located on http://webdavserver/mywebdavfolder/). In the case the second parameter is omitted, the API will pick the folder in which the file is located. For example, if your file URL is http://webdavserver/folder/document.ext it will mount http://webdavserver/folder/ in your file system. As a result, if this parameter is not specified, you may find several folders mount in your local file system after opening documents located in different folders.
  • Url of the Java Applet. If this parameter is omitted the API will use the following URL:
    '/plugins/ITHitMountOpenDocument.jar'

Note that MicrosoftOfficeEditDocument() is much faster comparing to JavaEditDocument() and does not require Java to be installed. However JavaEditDocument() is more universal and works with any file types and any on majority of OS that support Java.