user1956651
user1956651

Reputation: 1

How do I use the functionality of "P4 where" using the P4 .net API

The perforce command P4 where (Perforce Command Reference PDF) will give me the branch path, workspace path, and full local path of a specified file.

I would like to know how to access this functionality (specifically the full local path of a file) using the official .net API provided by perforce.

Upvotes: 0

Views: 938

Answers (2)

Newtopian
Newtopian

Reputation: 7732

a simpler way is to use the function GetClientFileMappings() from the client object.

API definition here

However I have found the function to be somewhat slow when querying a very large number of files (100k+). Still I highly recommend you batch your query rather than iterate and query. Otherwise works well.

Upvotes: 0

randy-wandisco
randy-wandisco

Reputation: 3659

Assuming you already have a connection object established in the .NET API, try this:

            string[] files = new string[1];
            files[0] = "//depot/Jam/MAIN/src/glob.c";
            P4Command cmd = new P4Command(pRep, "where", true, files);
            Options opts = new Options();

            //run command and get results
            P4CommandResult results = cmd.Run(opts);
            TaggedObjectList list = (results.TaggedOutput);
            foreach (TaggedObject obj in list)
            {
                foreach (String s in obj.Keys)
                {
                    String value = "n/a";
                    obj.TryGetValue(s, out value);
                    Console.Out.WriteLine(s + " = " + value);
                }
            }

That gives you output like this:

depotFile = //depot/Jam/MAIN/src/glob.c
clientFile = //bruno_ws/Jam/MAIN/src/glob.c
path = C:\P4DemoWorkspaces\bruno_ws\Jam\MAIN\src\glob.c

Upvotes: 1

Related Questions