Managing Custom Properties with JavaScript WebDAV Library

Using the library you can manage custom properties on a WebDAV server. Custom properties are supported by any Class 1 WebDAV server. Each custom property is represented by Property class and has name and value. Name of the property is represented by PropertyName class and has name and namespace.

Enumerating Custom Properties

To get all custom properties use HierarchyItem.GetAllPropertiesAsync method.

var webDavSession = new ITHit.WebDAV.Client.WebDavSession();
var sFileAbsolutePath = 'http://localhost:87654/myfile.txt';
var fCallback = function() {};

webDavSession.OpenFileAsync(sFileAbsolutePath, function(oFileAsyncResult) {

    /** @typedef {ITHit.WebDAV.Client.File} oFile */
    var oFile = oFileAsyncResult.Result;

    oFile.GetAllPropertiesAsync(function(oAsyncResult) {

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

        for (var i = 0, l = aProperties.length; i < l; i++) {
            console.log(aProperties[i].Name + ': ' + aProperties[i].StringValue());
        }

        fCallback(oAsyncResult);
    });
});

Adding and Updating Custom Properties

To add or update custom properties use HierarchyItem.UpdatePropertiesAsync method. Pass the array of properties as a first parameter.

var webDavSession = new ITHit.WebDAV.Client.WebDavSession();
var sFileAbsolutePath = 'http://localhost:87654/myfile.txt';
var fCallback = function() {};

webDavSession.OpenFileAsync(sFileAbsolutePath, function(oFileAsyncResult) {

    /** @typedef {ITHit.WebDAV.Client.File} oFile */
    var oFile = oFileAsyncResult.Result;

    var oPropertyName = new ITHit.WebDAV.Client.PropertyName('myname', 'mynamespace');
    var oProperty = new ITHit.WebDAV.Client.Property(oPropertyName, 'Test value');

    oFile.UpdatePropertiesAsync([oProperty], null, null, function(oAsyncResult) {

        if (oAsyncResult.IsSuccess) {
            console.log('Property `mynamespace:myname` successfully added to file!');
        }

        fCallback(oAsyncResult);
    });
});

Deleting Custom Properties

To delete custom properties pass array of properties as a second parameter to  HierarchyItem.UpdatePropertiesAsync method.

var webDavSession = new ITHit.WebDAV.Client.WebDavSession();
var sFileAbsolutePath = 'http://localhost:87654/myfile.txt';
var fCallback = function() {};

webDavSession.OpenFileAsync(sFileAbsolutePath, function(oFileAsyncResult) {

    /** @typedef {ITHit.WebDAV.Client.File} oFile */
    var oFile = oFileAsyncResult.Result;

    var oPropertyName = new ITHit.WebDAV.Client.PropertyName('myname', 'mynamespace');

    oFile.UpdatePropertiesAsync(null, [oPropertyName], null, function(oAsyncResult) {

        if (oAsyncResult.IsSuccess) {
            console.log('Property `mynamespace:myname` successfully deleted from file!');
        }

        fCallback(oAsyncResult);
    });
});