[This is preliminary documentation and is subject to change.]
Using P4API.NETClient programs interact with the Perforce server by:
-
Initializing a connection.
-
Sending commands.
-
Closing the connection.
To connect to the Perforce server, your client application must call the Connect() method; for example:

// initialize the connection variables // note: this is a connection without using a password string uri = "localhost:6666"; string user = "admin"; string ws_client = "admin_space"; // define the server, repository and connection Server server = new Server(new ServerAddress(uri)); Repository rep = new Repository(server); Connection con = rep.Connection; // use the connection varaibles for this connection con.UserName = user; con.Client = new Client(); con.Client.Name = ws_client; // connect to the server con.Connect(null);
To send commands to the Perforce server, your client can use P4 API.NET methods; for example:

// set the options for the p4 changes command string clientName = "admin_space"; int maxItems = 5; string userName = "admin"; Options opts = new Options(ChangesCmdFlags.LongDescription, clientName, maxItems, ChangeListStatus.None, userName); // run the command against the current repository IList<Changelist> changes = rep.getChangelists(opts); // changes will contain the data returned by the command // p4 changes -L -c admin_space -m 5 -u admin
To disconnect from the Perforce server, your client application must call the Disconnect() method; for example:

// disconnect from the server con.Disconnect(null);
To run commands that do not have methods in the .NET API, your client can use the P4Command.Run() method; for example:

// create a new command using parameters: // repository, command, tagged, arguments cmd = new P4Command((rep, "changes", true, null); Options opts = new Options(); opts["-m"] = 50; //run command and get results P4CommandResult results = cmd.Run(opts); // results will contain the data returned by the command // p4 -ztag changes -m 50