Page 1 of 1

How to detect if file is already checked out by someone?

Posted: Fri Aug 07, 2009 11:22 am
by mikesh
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?

Posted: Fri Aug 07, 2009 12:54 pm
by jeremy_sg
The easiest way is to use the Command Line client:

./vault.exe -host SERVER -user USERNAME -password PASSWORD -repository "Repository Name" listcheckouts

Re: How to detect if file is already checked out by someone?

Posted: Mon Aug 10, 2009 7:04 am
by mikesh
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?

Posted: Mon Aug 10, 2009 7:25 am
by jeremy_sg
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();
					}

Re: How to detect if file is already checked out by someone?

Posted: Mon Aug 10, 2009 9:56 am
by mikesh
Thanks for your help. Getting list of all checked out files works quickly enough, not as I expected.