You need, from C#, to execute a cleartool
command
More specifically, a descr
with a format option only displaying exactly what you are after.
cleartool descr -fmt "%Sn" youFileFullPath
That will return a string like /main/34
, meaning /branch/version
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo(@"cleartool");
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.Arguments = "descr -fmt \"%Sn\" \"" + yourFilePath + "\"";
psi.UseShellExecute = false;
System.Diagnostics.Process monProcess;
monProcess= System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput = monProcess.StandardOutput;
monProcess.WaitForExit();
if (monProcess.HasExited)
{
//la sortie du process est recuperee dans un string
string output = myOutput.ReadToEnd();
MessageBox.Show(output);
}
Note: it is recommended to always use double quotes around your file full path, in case that path or that file name includes spaces
As I have explained in this other ClearCase SO question, you could also use the CAL interface (COM object), but I have always found cleartool
(the basic CLI -- Command Line Interface --) more reliable especially when things go wrong: the error message is much more precise.