Opening Microsoft Office Documents and Other Types of Files for Editing From a Web Page

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. Editing MS Office documents are also supported on iOS, Android and Windows 10 S.

Opening Documents for Editing

To open the document for editing call the EditDocument() function passing document URL as a parameter and optionally mounting path and an error callback function:

<!DOCTYPE html>

<html lang="en" xmlns="">
    <meta charset="utf-8" />
    <script type="text/javascript" src="ITHitWebDAVClient.js" ></script>

    <script type="text/javascript">
        function edit() {
            ITHit.WebDAV.Client.DocManager.EditDocument("https://server/folder/file.docx", "/", protocolInstallCallback);
        // Called if protocol handler is not installed, for non-MS Office docs only.
        function protocolInstallCallback(message) {
           var installerFilePath = "/Plugins/" + ITHit.WebDAV.Client.DocManager.GetProtocolInstallFileNames()[0];
           if (confirm("This action requires a protocol installation. Select OK to download the protocol installer.")){
    <input type="button" value="Edit Document" onclick="edit()" />

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

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

  • In the case of a Microsoft Office document, the Ajax WebDAV Library is using a protocol handler installed by MS Office 2010 SP2 and later to open Microsoft Office documents for editing. This approach is available on Windows and Mac OS X only if MS Office 2010 SP2 and later is installed (MS Office 2011 or later in case of OS X). If document opening failed (for example if MS Office is not installed) the davX: protocol is used.
  • In the case of a non-Microsoft Office document, the WebDAV Ajax Library is using custom davX: protocol. This approach is available on Windows, Mac OS X, and Linux.

The EditDocument() function, as well as other functions in DocManager, are using a callback function to report if the required protocol is available on the client machine. If the protocol is not installed, the callback function is executed. In this callback, you will typically request a protocol installation. See more about protocol application detection and installation in this Protocol Application Detection and Installation article.

Important! Microsoft Office on Windows and OS X as well as Windows Shell (Web Folders / mini-redirector), requires secure SSL connection when used with Basic authentication. Microsoft Office will fail to open a document via an insecure connection with Basic authentication. For a workaround please see the following articles. In the case of MS Office on Windows: You cannot open Office file types directly from a server that only supports Basic Authentication over a non-SSL connection with Office applications. In the case of MS Office on OS X: You cannot open Office for Mac files directly from a server that supports only Basic authentication over a non-SSL connection.

Customizing Documents Opening

In case you wish to avoid using davX: protocol, you can use MicrosoftOfficeEditDocument() function call. This function can open MS Office documents only and is using protocol extensions installed by Microsoft Office 2010 SP2 and later. To find out if this type of document is an MS Office document call IsMicrosoftOfficeDocument() function:

var sDocumentUrl = "https://server/path/file.docx"; // this must be full path
var oNs = ITHit.WebDAV.Client.DocManager;
if (oNs.IsMicrosoftOfficeDocument(sDocumentUrl)) {
} else {
    oNs.DavProtocolEditDocument([sDocumentUrl], "/", protocolInstallCallback);

Note that this function does not support Microsoft Office 2010 SP1 and earlier versions.

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 use the DavProtocolEditDocument() or EditDocument() functions.

Associating File Extension with Microsoft Office

The functionality described in this paragraph is available in WebDAV Ajax Library v3.0.2209.0 and later versions.

If you wish to open a specific file type with Microsoft Office when calling EditDocument() or MicrosoftOfficeEditDocument() functions you must associate it with Microsoft office application using DocManager.MsOfficeEditExtensions static class. It provides arrays of extensions for each Microsoft Office application. For example to open .rtf files with Microsoft Word, add the rtf extension to the MsOfficeEditExtensions.Word array:

ITHit.WebDAV.Client.DocManager.EditDocument("https://serv/path/file.rtf", "/", protocolInstallMessage);
// or ITHit.WebDAV.Client.DocManager.MicrosoftOfficeEditDocument("https://serv/path/file.rtf");

You can also remove extensions from the arrays. In this case the DavX protocol will be used instead of MS Office to open the extension.

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 a self-signed certificate).

Using the davX: Protocol

In case you prefer using the davX: protocol, call the DavProtocolEditDocument() function.

The DavProtocolEditDocument() function is doing the following:

  1. Mounts WebDAV folder provided in the second parameter in your local file system. It will present the login dialog if required. The logic of the log-in dialog depends on the OS. On Windows and Mac OS X the OS-powered login will be displayed while on Linux the protocol application will present its own login dialog. The login dialog is presented only during the first document access.
  2. Executes default OS file open command.

The DavProtocolEditDocument() function accepts following parameters:

  • Document Urls. An array of documents to open. 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 filesystem. 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 https://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 https://webdavserver/folder/document.ext it will mount https://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.
  • Error callback. A callback function that will be called if the opening of the document failed. In this callback, you will typically request a protocol installation and will redirect to the installer that targets client OS.

Opening more than one document at a time

The functionality described in this paragraph is introduced in IT Hit WebDAV Ajax Library v5.11. In v5.3-v5.10 the first parameter was defined as a comma-separated list of documents.

Using the DavProtocolEditDocument() function you can open more than one document simultaneously. Due to the web browser protocol limitations you can not achieve the same functionality by calling DavProtocolEditDocument() / EditDocument() functions in a cycle. Instead, you must call DavProtocolEditDocument() passing a JavaScript array of document URLs. All documents must reside under the common root specified in sMountUrl parameter.

    ['https://server/dav/fldr1/doc1.ext','https://server/dav/fldr2/doc2.ext'], // Array of document URLs.
    'https://server/dav/',  // Mount URL, must be common for all docs in sDocumentUrls.
    protocolInstallMessage  // Function to call if protocol app is not installed.

Triggering 'Open With' dialog

The functionality described in this paragraph is introduced in IT Hit WebDAV Ajax Library v3 Beta.

Using the DavProtocolEditDocument() function you can trigger the system 'Open With' dialog, so the user can select the application to use for opening the document. To show 'Open With' pass the 'OpenWith' value to the sCommand parameter:

    ['https://server/dav/fldr1/doc1.ext'], // Document URL(s).
    'https://server/dav/',               // Mount URL.
    protocolInstallMessage,              // Function to call if protocol app is not installed.
    null,                                // Use Basic/Digest/NTLM/Kerberos, do not pass cookies.
    'OpenWith'                           // Command to execute.

The 'Open With' dialog is also automatically displayed for files with extensions that are not associated with any installed client application and for files without extensions.

The 'OpenWith' is supported on Windows and OS X only.

See Also:



Opening Photoshop Files for Editing from a Web Page | Opening Office Documents in a LibreOffice for Editing from a Web Page | Opening AutoCAD Files from a Web Page for Editing | Opening PDF File in Adobe Acrobat for Editing from a Web Page

Next Article:

Opening MS Office and other Docs from a Web Site with Cookies Authentication