Managing Custom Properties on a WebDAV Server Using .NET API

Enumerating Properties

string license = "<?xml version='1.0' encoding='u...
WebDavSession session = new WebDavSession(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IFile file = session.OpenFile(new Uri("http://server:8080/Library/1.txt"));

Property[] properties = file.GetAllProperties();
foreach(Property prop in properties)
{
    Console.WriteLine(prop.Name + " " + prop.StringValue);
}

Adding and Updating Properties

string license = "<?xml version='1.0' encoding='u...
WebDavSession session = new WebDavSession(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IFile file = session.OpenFile(new Uri("http://server:8080/Library/Products.docx"));

Property[] propsToAddAndUpdate = new Property[3];
propsToAddAndUpdate[0] = new Property(new PropertyName("Ammount", "Sales"), "1200");
propsToAddAndUpdate[1] = new Property(new PropertyName("ManagerApproved", "Sales"), "Yes");
propsToAddAndUpdate[2] = new Property(new PropertyName("Branch", "Sales"), "EMEA Region");

file.UpdateProperties(propsToAddAndUpdate, null);

Deleting Properties

string license = "<?xml version='1.0' encoding='u...
WebDavSession session = new WebDavSession(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IFile file = session.OpenFile(new Uri("http://server:8080/Library/Products.docx"));

PropertyName[] propsToDelete = new PropertyName[3];
propsToDelete[0] = new PropertyName("Ammount", "Sales");
propsToDelete[1] = new PropertyName("ManagerApproved", "Sales");
propsToDelete[2] = new PropertyName("Branch", "Sales");

file.UpdateProperties(null, propsToDelete);

Analyzing Which Properties Failed to Add/Update/Delete

try
{
    file.UpdateProperties(propsToAddAndUpdate, propsToDelete);
}
catch (PropertyException ex)
{
    Console.WriteLine(ex.Message + " " + ex.Status.Code + " " + ex.Status.Description);
    // Find which properties failed to add/update/delete
    foreach (IPropertyMultistatusResponse propInfo in ex.Multistatus.Responses)
    {
        Console.WriteLine(propInfo.PropertyName + " " + propInfo.Status.Code + " " + propInfo.Status.Description);
    }
}