<html dir="LTR">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252" />
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5" />
<title>P4Connection Class</title>
<xml>
</xml>
<link rel="stylesheet" type="text/css" href="MSDN.css" />
</head>
<body id="bodyID" class="dtBODY">
<div id="nsbanner"> <div id="bannerrow1">
<table class="bannerparthead" cellspacing="0" id="Table1">
<tr id="hdr">
<td class="runninghead">Perforce API for the .Net CLR</td>
<td class="product"><img alt="P4.Net" src="p4net.GIF" /></td>
</tr>
</table>
</div>
<div id="TitleRow">
<h1 class="dtH1">P4Connection Class</h1>
</div>
</div>
<div id="nstext">
<p> A connection to a Perforce server instance. </p>
<p>For a list of all members of this type, see <a href="P4API.P4ConnectionMembers.html">P4Connection Members</a>.</p>
<p>
<a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemObjectClassTopic.htm">System.Object</a>
<br /><b>P4API.P4Connection</b></p>
<div class="syntax">
<span class="lang">[VisualBasic]</span>
<br />PublicClassP4Connection<div>Implements<a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemIDisposableClassTopic.htm">IDisposable</a></div></div>
<div class="syntax">
<span class="lang">[C#]</span>
<div>publicclassP4Connection<b> : <a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemIDisposableClassTopic.htm">IDisposable</a></b></div>
</div>
<h4 class="dtH4">Remarks</h4>
<p> 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: </p>
<pre class="code" language="C#" escaped="true">P4Connection p4 = new P4Connection();
p4.Connect();
// Run some commands
p4.Disconnect();</pre>
<p> 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. </p>
<p> 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). </p>
<p>From the command line:</p>
<pre class="code" language="C#">c:\> p4 changes -m1 -s submitted //depot/path/...</pre>
<p>From P4.Net:</p>
<pre class="code" language="C#" escaped="true">P4Connect p4 = new P4Connection();
p4.Connect();
P4Recordset changes = p4.Run("changes", "-m1", "-s", "submitted", "//depot/path/...");
p4.Disconnect();</pre>
<p> If you dont know what all the arguments for p4 changes mean, then <code>p4 help changes</code> is your best friend. The first step in building anything with P4.Net, is to know the exact command lines youd run manually. </p>
<h4 class="dtH4">Requirements</h4><p><b>Namespace: </b><a href="P4API.html">P4API</a></p><p><b>Assembly: </b>p4api (in p4api.dll)
</p><h4 class="dtH4">See Also</h4><p><a href="P4API.P4ConnectionMembers.html">P4Connection Members</a> | <a href="P4API.html">P4API Namespace</a></p><object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e" viewastext="true" style="display: none;"><param name="Keyword" value="P4Connection class, about P4Connection class"></param></object><hr /><div id="footer"><p><a href="Copyright.html">Copyright 2006 Shawn Hladky</a></p><p></p></div></div>
</body>
</html>