A connection to a Perforce server instance.

Namespace:  P4API
Assembly:  p4api (in p4api)
Version: 1.0.0.0 (1.0.0)

Syntax

C#
public class P4Connection : IDisposable

Remarks

The P4Connection class is the main player in P4.Net. This represents a connection to the Perforce server. Every utility that uses P4.Net will have some variation of the following code:

CopyC#
P4Connection p4 = new P4Connection();
p4.Connect();

// Run some commands
p4.Disconnect();

Rule number 1: Always remember to disconnect. This frees unmanaged memory, and cleanly disconnects from the Perforce server. P4Connection implements IDisposable, and the Dispose and Disconnect methods can be used interchangeably.

P4.Net is based off the command-line syntax (as are most other Perforce APIs). Almost all of the commands you issue in P4.Net will use the same arguments as the p4 client executable. For example, say you need to find the latest submitted changelist under a given path (//depot/path).

From the command line:

CopyC#
c:\> p4 changes -m1 -s submitted //depot/path/...

From P4.Net:

CopyC#
P4Connect p4 = new P4Connection();
p4.Connect();
P4Recordset changes = p4.Run("changes", "-m1", "-s", "submitted", "//depot/path/...");
p4.Disconnect();

If you don’t know what all the arguments for p4 changes mean, then p4 help changes is your best friend. The first step in building anything with P4.Net, is to know the exact command lines you’d run manually.

Inheritance Hierarchy

System..::.Object
  P4API..::.P4Connection

See Also