How do I list the available labels of a Project?

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

Moderator: SourceGear


Posts: 23
Joined: Fri Oct 18, 2013 1:18 pm
PostPosted: Wed Jul 06, 2016 3:35 am
It's my first time I develop a .NET winforms application using Vault Client functionalities.
I want to use Vault Client API to get a list of the labels per project.

I found the method ServerOperations.ProcessCommandFindLabels() in VaultClientIntegrationLib.dll but I don't have any clue how the parameters should look like to get a successful result.

Any help is appreciated.

Posts: 8448
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
PostPosted: Wed Jul 06, 2016 2:08 pm
You could try using the command-line client in a script and the FindLabels command. There is a -patternmath option where you can use wildcards.

Or, in the API download is the code used for the CLC, so you can see exactly how we used ProcessCommandFindLabels in the CLC. It should look like:
int nRetCode = ServerOperations.ProcessCommandFindLabels(strSearchString, strReposPath, _args.Recursive, _args.HistoryRowLimit, _args.MatchCase, _args.MatchWord, pm, out arLabelItems);

Here's a basic example...

VaultLabelItemX[] arLabelItems = null;
int nRetCode = ServerOperations.ProcessCommandFindLabels("myLabel", "$/folder1", true, 1000, true, true, false, out arLabelItems);
Beth Kieler
SourceGear Technical Support

Posts: 23
Joined: Fri Oct 18, 2013 1:18 pm
PostPosted: Thu Jul 07, 2016 1:39 am
Thank you Beth for the example. But is there a simple way to list all available Labels of a project?
Something like:
GetAllLabelsOfProject(strProjectPath) --> which returns a list of all Labels...

Posts: 23
Joined: Fri Oct 18, 2013 1:18 pm
PostPosted: Thu Jul 07, 2016 3:21 am
After many attempts I was able to get all labels of a project by running the code below.

I added two dll's (VaultLib.dll and VaultClientIntegrationLib.dll) in the References in Visual Studio Project and added

Code: Select all
using VaultLib;
using VaultClientIntegrationLib;

Code: Select all
ServerOperations.client.LoginOptions.URL = url;
ServerOperations.client.LoginOptions.User = user;
ServerOperations.client.LoginOptions.Password = pass;
ServerOperations.client.LoginOptions.Repository = rep;
ServerOperations.Login();
ServerOperations.client.AutoCommit = true;

string prjPath = "$/projectpath";
VaultLabelItemX[] arLabelItems = null;

int nRetCode = ServerOperations.ProcessCommandFindLabels("*", prjPath, false, 1000, true, true, VaultFindInFilesDefine.PatternMatch.Wildcard, out arLabelItems);

MessageBox.Show(arLabelItems.Count().ToString()); // Print how much labels found

foreach (var item in arLabelItems)
{
   MessageBox.Show(arLabelItems[i].Label.ToString()); // Show Label
}
Last edited by Tanguy on Fri Jul 08, 2016 12:55 am, edited 1 time in total.

Posts: 8448
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
PostPosted: Thu Jul 07, 2016 7:30 am
Thank you for the update.
Beth Kieler
SourceGear Technical Support

Return to Questions (API)

Who is online

Users browsing this forum: No registered users and 1 guest