Class: WebDavSession

WebDavSession Class

Session for accessing WebDAV servers.

Namespace

ITHit.WebDAV.Client

new ITHit.WebDAV.Client.WebDavSession()

Fires:
Example
<!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">
         var sFolderUrl = 'http://localhost:35829/';
         var oSession = new ITHit.WebDAV.Client.WebDavSession();

         oSession.OpenFolderAsync(sFolderUrl, null, function (oFolderAsyncResult) {
             if (!oFolderAsyncResult.IsSuccess) {
                 console.error(oFolderAsyncResult.Error);
                 return;
              }

             /** @typedef {ITHit.WebDAV.Client.Folder} oFolder */
             var oFolder = oFolderAsyncResult.Result;

             console.log(oFolder.Href);

             oFolder.GetChildrenAsync(false, null, function (oAsyncResult) {
                 if (!oAsyncResult.IsSuccess) {
                     console.error(oFolderAsyncResult.Error);
                     return;
                 }

                 /** @typedef {ITHit.WebDAV.Client.HierarchyItem[]} aHierarchyItems */
                 var aHierarchyItems = oAsyncResult.Result;

                 for (var i = 0, l = aHierarchyItems.length; i < l; i++) {
                     var sSize = aHierarchyItems[i].ResourceType !== ITHit.WebDAV.Client.ResourceType.Folder ?
                         Math.round(aHierarchyItems[i].ContentLength / 1000) + ' Kb' :
                         null;
                     console.log(' [' + aHierarchyItems[i].ResourceType + '] ' + aHierarchyItems[i].DisplayName + (sSize ? ', ' + sSize : ''));
                 }
             });
         });
     </script>
 </head>
 <body>
 </body>
 </html>

Members

staticITHit.WebDAV.Client.WebDavSession.ProtocolVersion

Protocol Version of AJAX Library

staticITHit.WebDAV.Client.WebDavSession.Version

Version of AJAX Library

Methods

AddListener(sEventName, fCallback, oContext)

Name Type Description
sEventName string
fCallback
oContext object optional

CreateFolderAsync(sPath, aProperties, fCallback)

Creates folder corresponding to path.
Name Type Description
sPath string Path to the resource.
aProperties Array.<ITHit.WebDAV.Client.PropertyName> Additional properties requested from server. Default is empty array.
fCallback ITHit.WebDAV.Client.WebDavSession~CreateFolderAsyncCallback Function to call when operation is completed.

OpenFile(sPath, aProperties){ITHit.WebDAV.Client.File}

Load File object corresponding to path.
Name Type Description
sPath string Path to the file.
aProperties Array.<ITHit.WebDAV.Client.PropertyName> optional Additional properties requested from server. Default is empty array.
Deprecated
Use asynchronous method instead
Throws:
  • ITHit.WebDAV.Client.Exceptions.UnauthorizedException Incorrect credentials provided or insufficient permissions to access the requested item.
  • ITHit.WebDAV.Client.Exceptions.NotFoundException The requested file doesn't exist on the server.
  • ITHit.WebDAV.Client.Exceptions.ForbiddenException The server refused to fulfill the request.
  • ITHit.WebDAV.Client.Exceptions.WebDavException Unexpected error occurred.
Returns:
ITHit.WebDAV.Client.File File corresponding to requested path.

OpenFileAsync(sPath, aProperties, fCallback){ITHit.WebDAV.Client.Request}

Load File object corresponding to path.
Name Type Description
sPath string Path to the file.
aProperties Array.<ITHit.WebDAV.Client.PropertyName> Additional properties requested from server. Default is empty array.
fCallback ITHit.WebDAV.Client.WebDavSession~OpenFileAsyncCallback Function to call when operation is completed.
Returns:
ITHit.WebDAV.Client.Request Request object.

OpenFolder(sPath, aProperties){ITHit.WebDAV.Client.Folder}

Returns Folder object corresponding to path.
Name Type Description
sPath string Path to the folder.
aProperties Array.<ITHit.WebDAV.Client.PropertyName> optional Additional properties requested from server. Default is empty array.
Deprecated
Use asynchronous method instead
Throws:
  • ITHit.WebDAV.Client.Exceptions.UnauthorizedException Incorrect credentials provided or insufficient permissions to access the requested item.
  • ITHit.WebDAV.Client.Exceptions.NotFoundException The requested folder doesn't exist on the server.
  • ITHit.WebDAV.Client.Exceptions.ForbiddenException The server refused to fulfill the request.
  • ITHit.WebDAV.Client.Exceptions.WebDavException Unexpected error occurred.
Returns:
ITHit.WebDAV.Client.Folder Folder corresponding to requested path.

OpenFolderAsync(sPath, aProperties, fCallback)

Returns Folder object corresponding to path.
Name Type Description
sPath string Path to the folder.
aProperties Array.<ITHit.WebDAV.Client.PropertyName> Additional properties requested from server. Default is empty array.
fCallback ITHit.WebDAV.Client.WebDavSession~OpenFolderAsyncCallback Function to call when operation is completed.
Example
var webDavSession = new ITHit.WebDAV.Client.WebDavSession();
var sFolderAbsolutePath = 'http://localhost:87654/Documents/';
var fCallback = function() {};

webDavSession.OpenFolderAsync(sFolderAbsolutePath, null, function(oAsyncResult) {

    /** @typedef {ITHit.WebDAV.Client.Folder} oFolder */
    var oFolder = oAsyncResult.Result;

    console.log('Loaded folder `' + oFolder.DisplayName + '`.');

    fCallback(oAsyncResult);
});

OpenItem(sPath, aProperties){ITHit.WebDAV.Client.HierarchyItem}

Returns HierarchyItem object corresponding to path.
Name Type Description
sPath string Path to the item.
aProperties Array.<ITHit.WebDAV.Client.PropertyName> optional Additional properties requested from server. Default is empty array.
Deprecated
Use asynchronous method instead
Throws:
  • ITHit.WebDAV.Client.Exceptions.UnauthorizedException Incorrect credentials provided or insufficient permissions to access the requested item.
  • ITHit.WebDAV.Client.Exceptions.NotFoundException The requested folder doesn't exist on the server.
  • ITHit.WebDAV.Client.Exceptions.ForbiddenException The server refused to fulfill the request.
  • ITHit.WebDAV.Client.Exceptions.WebDavException Unexpected error occurred.
Returns:
ITHit.WebDAV.Client.HierarchyItem Item corresponding to requested path.

OpenItemAsync(sPath, aProperties, fCallback)

Returns HierarchyItem object corresponding to path.
Name Type Description
sPath string Path to the resource.
aProperties Array.<ITHit.WebDAV.Client.PropertyName> Additional properties requested from server. Default is empty array.
fCallback ITHit.WebDAV.Client.WebDavSession~OpenItemAsyncCallback Function to call when operation is completed.

RemoveListener(sEventName, fCallback, oContext)

Name Type Description
sEventName string
fCallback
oContext object optional

Type Definitions

CreateFolderAsyncCallback(oResult)

Callback function to be called when folder creates on server.
Name Type Description
oResult ITHit.WebDAV.Client.AsyncResult Result object
Name Type Description
Result ITHit.WebDAV.Client.HierarchyItem Item corresponding to requested path.

OpenFileAsyncCallback(oResult)

Callback function to be called when file loaded from server.
Name Type Description
oResult ITHit.WebDAV.Client.AsyncResult Result object
Name Type Description
Result ITHit.WebDAV.Client.File File corresponding to requested path.

OpenFolderAsyncCallback(oResult)

Callback function to be called when folder loaded from server.
Name Type Description
oResult ITHit.WebDAV.Client.AsyncResult Result object
Name Type Description
Result ITHit.WebDAV.Client.Folder Folder corresponding to requested path.

OpenItemAsyncCallback(oResult)

Callback function to be called when items loaded from server.
Name Type Description
oResult ITHit.WebDAV.Client.AsyncResult Result object
Name Type Description
Result ITHit.WebDAV.Client.HierarchyItem Item corresponding to requested path.

Events

OnBeforeRequestSend

The OnBeforeRequestSend event is fired before request is being submitted to server and provides all information that is used when creating the request such as URL, HTTP verb, headers and request body.
Properties:
Name Type Description
Method string Request method
Href string Request absolute path
Headers object Key-value object with headers
Body string Request Body
Example
var webDavSession = new ITHit.WebDAV.Client.WebDavSession();
var fCallback = function() {};

webDavSession.AddListener('OnBeforeRequestSend', function(oEvent) {

    // Add new header
    //oEvent.Headers['My-Header'] = oEvent.Method;

    // Show request info
    console.log(oEvent.Method + ' ' + oEvent.Href);
    for (var sKey in oEvent.Headers) {
        if (oEvent.Headers.hasOwnProperty(sKey)) {
            console.log(sKey + ': ' + oEvent.Headers[sKey]);
        }
    }

    // Show request body
    console.log(oEvent.Body);

    fCallback(oEvent);
});

OnResponse

The OnResponse event fires when the data is received from server. In your event handler you can update any data received from server.
Properties:
Name Type Description
Status number Response status code
StatusDescription string Response status description
Headers object Key-value object with headers
Body string Response Body
Example
var webDavSession = new ITHit.WebDAV.Client.WebDavSession();
var fCallback = function() {};

webDavSession.AddListener('OnResponse', function(oEvent) {

    // Show HTTP status and description
    console.log(oEvent.Status + ' ' + oEvent.StatusDescription);

    // Show headers
    for (var sKey in oEvent.Headers) {
        if (oEvent.Headers.hasOwnProperty(sKey)) {
            console.log(sKey + ': ' + oEvent.Headers[sKey]);
        }
    }

    // Show response body
    console.log(oEvent.BodyText);

    fCallback(oEvent);
});