Click or drag to resize

IHierarchyItemLockAsync Method

IT Hit WebDAV Classes Reference
Locks the item.

Namespace:  ITHit.WebDAV.Client
Assembly:  ITHit.WebDAV.Client (in ITHit.WebDAV.Client.dll) Version: 6.0.4052-Beta
Syntax
Task<LockInfo> LockAsync(
	LockScope lockScope,
	bool deep,
	string owner,
	Nullable<TimeSpan> timeout,
	IDictionary<string, string> headers = null,
	CancellationToken cancellationToken = null
)

Parameters

lockScope
Type: ITHit.WebDAV.ClientLockScope
Scope of the lock.
deep
Type: SystemBoolean
Whether to lock entire subtree.
owner
Type: SystemString
Owner of the lock.
timeout
Type: SystemNullableTimeSpan
TimeOut after which lock expires. Set to TimeSpan.MaxValue for infinity.
headers (Optional)
Type: System.Collections.GenericIDictionaryString, String
Request headers.
cancellationToken (Optional)
Type: System.ThreadingCancellationToken
Propagates notification that operations should be canceled.

Return Value

Type: TaskLockInfo
Instance of LockInfo with information about created lock.
Exceptions
ExceptionCondition
PreconditionFailedException The included lock token was not enforceable on this resource or the server could not satisfy the request in the lockinfo XML element.
LockedExceptionThe resource is locked. The method has been rejected.
MethodNotAllowedExceptionThe item does not support locking.
NotFoundExceptionThe item doesn't exist on the server.
WebDavHttpExceptionServer returned unknown error.
WebDavExceptionUnexpected error occurred.
Remarks
Server can set lock with different timeout than the one was asked.
Examples
string license = "<?xml version='1.0' encoding='utf...
WebDavSession session = new WebDavSession(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IHierarchyItem item = await session.GetFileAsync(new Uri("https://server:8580/Products/Sales.txt"));

LockInfo lockInfo = null;
try
{
    lockInfo = await item.LockAsync(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