IHierarchyItem.Lock Method 

IT Hit WebDAV for .NET

Locks the item.

[Visual Basic]
Function Lock( _
   ByVal lockScope As LockScope, _
   ByVal deep As Boolean, _
   ByVal owner As String, _
   ByVal timeout As TimeSpan _
) As LockInfo
[C#]
LockInfo Lock(
   LockScope lockScope,
   bool deep,
   string owner,
   TimeSpan timeout
);

Parameters

lockScope
Scope of the lock.
deep
Whether to lock entire subtree.
owner
Owner of the lock.
timeout
TimeOut after which lock expires.

Return Value

Instance of LockInfo with information about created lock.

Remarks

Server can set lock with different timeout than the one was asked.

Exceptions

Exception Type Condition
PreconditionFailedException The included lock token was not enforceable on this resource or the server could not satisfy the request in the lockinfo XML element.
LockedException The resource is locked. The method has been rejected.
MethodNotAllowedException The item does not support locking.
NotFoundException The item doesn't exist on the server.
WebDavHttpException Server returned unknown error.
WebDavException Unexpected error occurred.

Example

 string license = "<?xml version='1.0' encoding='utf...
 WebDavSession session = new WebDavSession(license);
 session.Credentials = new NetworkCredential("User1", "pwd");
 IHierarchyItem item = session.OpenResource(new Uri("http://server:8580/Products/Sales.txt"));

 LockInfo lockInfo = null;
 try
 {
     lockInfo = item.Lock(LockScope.Shared, false, "User 1", TimeSpan.MaxValue);
 }
 catch (LockedException)
 {
     Console.Write("The item is locked.");
 }
 catch (MethodNotAllowedException)
 {
     Console.Write("The item does not alow locks.");
 }
 if (lockInfo!= null)
 {
     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);
 }
 

See Also

IHierarchyItem Interface | ITHit.WebDAV.Client Namespace