Getting Started with JavaScript WebDAV Library

Download the library here and add <script> tag referencing ITHitWebDAVClient.js to your web page. The ITHitWebDAVClient.js is fully functional and does not have any limitations. However, the trial period is limited to 1 month. After the trial period expires the API will stop working. The license file is NOT required to activate the product (neither trial nor paid version).

Listing Folder Content

An example below lists folder content. You can browse folders without reloading a web page. It also adds buttons for opening documents in associated application and running OS file manager.

<!DOCTYPE html>

<html lang="en">
<head>
    <title>IT Hit WebDAV Ajax Library</title>
    <script src="http://www.ajaxbrowser.com/ITHitService/WebDAVAJAXLibrary/ITHitWebDAVClient.js" type="text/javascript"></script>
    <script type="text/javascript">

        // Lists files on a WebDAV server using WebDAV Ajax Library
        function ListFolder(sFolderUrl) {

            var ns = ITHit.WebDAV.Client;
            var session = new ns.WebDavSession();
            session.OpenFolderAsync(sFolderUrl,

                function (asyncResult) {

                    if (!asyncResult.IsSuccess) {
                        ProcessError(asyncResult.Error);
                        return;
                    }

                    var folder = asyncResult.Result;
                    folder.GetChildrenAsync(false,

                        function (asyncResult) {

                            if (!asyncResult.IsSuccess) {
                                ProcessError(asyncResult.Error);
                                return;
                            }

                            var items = asyncResult.Result;
                            var content = document.getElementById("folderContent");
                            var rows = "";
                            for (var i = 0; i < items.length; i++) {
                                var item = items[i];
                                rows += "<tr>"
                                    + "<td><a " + (item.ResourceType == ns.ResourceType.Folder ? "href='javascript:ListFolder(\"" + item.Href + "\")'" : "") + ">" + item.DisplayName + "</a></td>"
                                    + "<td class='alignRight'>" + (item.ResourceType == ns.ResourceType.Folder ? "" : item.ContentLength) + "</td>"
                                    + "<td class='alignRight'>" + item.LastModified.toLocaleString() + "</td>"
                                    + "<td>" + ((item.ResourceType == ns.ResourceType.Folder)
                                        ? "<a href='javascript: OpenFolder(\"" + item.Href + "\")' title='Open folder in OS File Manager'>Browse</a>"
                                        : "<a href='javascript: EditDoc(\"" + item.Href + "\")' title='Edit in associated application'>Edit</a>")
                                    + "</td>"
                                    + "</tr>";
                            }
                            content.innerHTML =
                                "<table><thead><tr><td>Name</td><td class='alignRight'>Size, b</td><td class='alignRight'>Modified</td><td></td></tr></thead>"
                                + rows
                                + "</table>";
                        }
                        );
                }
                );
        }

        function ProcessError(err) {
            alert(err.Status.Code + " " + err.Status.Description + "\n" + err.Message);
        }

        // Opens document for editing using MS Office or dav: protocol
        // sDocumentUrl must be full path including domain name: http://webdavserver.com/path/file.ext
        function EditDoc(sDocumentUrl) {
            ITHit.WebDAV.Client.DocManager.EditDocument(sDocumentUrl, "/", ProtocolInstallCallback);
        }

        // Opens folder in OS file manager
        // sFolderUrl must be full path including domain name: http://webdavserver.com/path/
        function OpenFolder(sFolderUrl) {
            ITHit.WebDAV.Client.DocManager.OpenFolderInOsFileManager(sFolderUrl, "/", ProtocolInstallCallback);
        }
            
        // Called if protocol handler is not installed
        function ProtocolInstallCallback(message) {
            var installerFilePath = "http://www.ajaxbrowser.com/ITHitService/WebDAVAJAXLibrary/Plugins/" + 
                ITHit.WebDAV.Client.DocManager.GetInstallFileName();
            
            if (confirm("This action requires a protocol installation. Select OK to download the protocol installer.")){
                window.open(installerFilePath);
            }
        }                        
    </script>
    <style type="text/css">
        .alignRight {text-align: right;}
        #folderContent thead td {font-weight: bolder;}
        #folderContent td {padding-right: 20px;}
    </style>
</head>
<body onload="ListFolder(window.location.href)">
    <p id="folderContent"></p>
</body>
</html> 

For the case of simplicity, the above example does not deal with web browser history back and forward buttons. In the real life, you will save your current location in URL hash and load it in the web browser load event.

Authentication and SSL

The library supports SSL as well as any authentication supported by a browser. You will usually rely on a browser authentication mechanisms and do not need to care about authentication. The browser will pop the login dialog when required, requesting for credentials. The browser will keep the credentials and use it when necessary automatically.

Important! Microsoft Edge, Microsoft Internet Explorer, 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. For a workaround please see the following articles. In case of 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 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.