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

Post your questions regarding using the Vault and Fortress API in your programs.

Moderator: SourceGear

Post Reply
mikesh
Posts: 3
Joined: Fri Aug 07, 2009 9:26 am

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

Post by mikesh » Fri Aug 07, 2009 11:22 am

I need to know the file state. If file is checked out and user name who checked out it. Would you help me?

jeremy_sg
Posts: 1821
Joined: Thu Dec 18, 2003 11:39 am
Location: Sourcegear
Contact:

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

Post by jeremy_sg » Fri Aug 07, 2009 12:54 pm

The easiest way is to use the Command Line client:

./vault.exe -host SERVER -user USERNAME -password PASSWORD -repository "Repository Name" listcheckouts
Subscribe to the Fortress/Vault blog

mikesh
Posts: 3
Joined: Fri Aug 07, 2009 9:26 am

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

Post by mikesh » Mon Aug 10, 2009 7:04 am

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?

jeremy_sg
Posts: 1821
Joined: Thu Dec 18, 2003 11:39 am
Location: Sourcegear
Contact:

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

Post by jeremy_sg » Mon Aug 10, 2009 7:25 am

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

mikesh
Posts: 3
Joined: Fri Aug 07, 2009 9:26 am

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

Post by mikesh » Mon Aug 10, 2009 9:56 am

Thanks for your help. Getting list of all checked out files works quickly enough, not as I expected.

Post Reply