How to detect if file is already checked out by someone?
Moderator: SourceGear
How to detect if file is already checked out by someone?
I need to know the file state. If file is checked out and user name who checked out it. Would you help me?
Re: How to detect if file is already checked out by someone?
The easiest way is to use the Command Line client:
./vault.exe -host SERVER -user USERNAME -password PASSWORD -repository "Repository Name" listcheckouts
./vault.exe -host SERVER -user USERNAME -password PASSWORD -repository "Repository Name" listcheckouts
Subscribe to the Fortress/Vault blog
Re: How to detect if file is already checked out by someone?
I want to do it using vault API not command line client. I can get list of all checked out files using ServerOperations.ProcessCommandListCheckOuts method. And then search my file in this list. But maybe direct way exist without getting all checked out files?
Re: How to detect if file is already checked out by someone?
The command line just calls ProcessCommandListCheckOuts under the hood. That is the command that you should use. There is no easy way to return just the checkouts for one user. Here's an example of how to work with the returned list (taken from XMLOutput.cs in the VaultClientAPI zip file)
Code: Select all
foreach (VaultClientCheckOutItem item in checkOuts)
{
xml.WriteStartElement("checkoutitem");
xml.WriteElementString("id", item.FileID.ToString());
foreach (VaultClientCheckOutUser user in item.CheckOutUsers)
{
xml.WriteStartElement("checkoutuser");
xml.WriteElementString("username", user.Name);
xml.WriteElementString("version", user.Version.ToString());
xml.WriteElementString("repositorypath", user.RepPath);
switch (user.LockType)
{
case VaultCheckOutType.None:
xml.WriteElementString("locktype", "none");
break;
case VaultCheckOutType.CheckOut:
xml.WriteElementString("locktype", "checkout");
break;
case VaultCheckOutType.Exclusive:
xml.WriteElementString("locktype", "exclusive");
break;
default:
xml.WriteElementString("locktype", "unknown");
break;
}
xml.WriteElementString("comment", user.Comment);
xml.WriteElementString("hostname", user.Hostname);
xml.WriteElementString("localpath", user.LocalPath);
xml.WriteElementString("folderid", user.FolderID.ToString());
xml.WriteElementString("lockedwhen", user.LockedWhen.ToString());
xml.WriteElementString("miscinfo", user.MiscInfo);
xml.WriteEndElement();
}
Subscribe to the Fortress/Vault blog
Re: How to detect if file is already checked out by someone?
Thanks for your help. Getting list of all checked out files works quickly enough, not as I expected.