Namespace: ITHit.WebDAV.Client
Task<LockInfo> LockAsync( LockScope lockScope, bool deep, string owner, Nullable<TimeSpan> timeout )
Exception | 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. |
string license = "<?xml version='1.0' encoding='utf... WebDavSessionAsync session = new WebDavSessionAsync(license); session.Credentials = new NetworkCredential("User1", "pwd"); IHierarchyItemAsync item = await session.OpenFileAsync(new Uri("http://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); }