Home
english
Home
.NET Server
Java Server
.NET Client
AJAX Client
AJAX Browser
Map Drive
Pricing
Contacts
info@ithit.com



Locking WebDAV Items

Locking prevents item from being modified by other users.

Probing Locks Support

Item can support exclusive, shared locks or do not support any locks. If you set exclusive lock other users will not be able to set any locks. If you set shared lock other users will be able to set shared lock on the item. To find out what locks are supported by the item use IHierarchyItem.SupportedLock property.

string license = "<?xml version='1.0' encoding='u...

WebDavSession session = new WebDavSession(license);

session.Credentials = new NetworkCredential("User1", "pwd");

IHierarchyItem item = session.OpenItem("http://server:8580/LargeFile.msi");

 

if(item.SupportedLock.Length==0)

    Console.WriteLine("Locks are not supported.");

foreach(LockScope lockScope in item.SupportedLock)

{

    if(lockScope == LockScope.Exclusive)

        Console.WriteLine("Item supports exclusive locks.");

    if(lockScope == LockScope.Shared)

        Console.WriteLine("Item supports shared locks.");

}

Locking Items

While locking you can pass to server following additional information about the lock:

  • Specify if the lock is shared or exclusive.
  • Specify if the lock applied only to this item or to the entire subtree.
  • Name of the user that applies lock.
  • Time when lock expires. To specify that lock should never expire pass TimeSpan.MaxValue.

IHierarchyItem item = session.OpenResource(new Uri("http://server:8580/Sales.txt"));

LockInfo lockInfo = item.Lock(LockScope.Shared, false, "User 1", new TimeSpan(0, 20, 0));

If the lock was successfully applied the server will return lock token. The lock token is a string (usually GUID) uniquely identifying the lock. You will pass this lock token back to server when unlocking the item.

To modify the locked item you must pass the lock token with an update request. All API methods that modify item content or properties provide overloaded instance to pass the lock token:

IHierarchyItem item = session.OpenResource(new Uri("http://server:8580/Sales.txt"));

IFolder destFolder = session.OpenFolder(new Uri("http://server:8580/Info/"));

 

LockInfo lockInfo = item.Lock(LockScope.Shared, false, "User 1", new TimeSpan(0, 20, 0));

item.CopyTo(destFolder, "Copy of " + item.DisplayName, false, false);

item.Unlock(lockInfo.LockToken.LockToken);

Using the API you can also request a list of lock tokens applied to the item:

IHierarchyItem item = session.OpenFolder(new Uri("http://server:8580/Products/"));

foreach (LockInfo lockInfo in item.ActiveLocks)

{

    string timout = lockInfo.TimeOut == TimeSpan.MaxValue ? "Infinite" : lockInfo.TimeOut.TotalSeconds.ToString();

    Console.WriteLine(lockInfo.Owner

        + " " + lockInfo.LockToken.Href

        + " " + lockInfo.LockToken.LockToken

        + " " + lockInfo.LockScope

        + " " + lockInfo.Deep

        + " " + timout);

}


What WebDAV software would you like to have?

Selected Customers:
Country: Norway
DnB NOR Group
Country: Finland
Bank of Finland
Country: United Kingdom
Bechtle Direct
Country: Sweden
BT Industries
Country: USA
California Chamber of Commerce
Country: Denmark
Danfoss Group
Country: Denmark
DFDS
Country: USA
Fluke Networks
Country: USA
HNI Corporation
Country: USA
IHS Inc
Country: USA
LandAmerica Financial Group
Country: Canada
Laurentian University
Country: USA
Microsoft
Country: Israel
RADVISION
Country: Ukraine
Raiffeisen Bank
Country: Netherlands
Sanoma Uitgevers
Country: USA
Siemens
Country: Australia
WorkCover NSW
Country: Ukraine
OTP Bank
Country: USA
Intel Corporation
Country: Austria
Austrian Federal Railways
Home .NET Server Java Server .NET Client AJAX Client AJAX Browser Map Drive Pricing Contacts

Updated: Sunday, October 26, 2008