Home > C/C++ > Perforce with C# (p4 dotnet)

Perforce with C# (p4 dotnet)

I’ve found a need to use Perforce with C# recently. The first step was to get the right DLLs for the job. I got the P4 API DLL from SourceForge here

Extracting it, I think you actually only need the p4API dll in the bin/CLR_2.0 directory, I took the whole directory just in case.

In your project right click on the References directory and ‘Add Reference’ and navigate to the p4api.dll.

// Load up the API
using P4API;
...

// Create the connection
P4Connection p4 = null;
            try
            {
                p4 = new P4Connection(); // Uses the default connection to Perforce        
                p4.Connect();

                // Don't throw an exception on a Perforce error.  We handle these manually.
                p4.ExceptionLevel = P4ExceptionLevels.NoExceptionOnErrors;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

I want to delete a file from the repository so to do this I needed to just put through the right call. From what I’ve gathered you can run any P4 command that can be run via the command line, all you need to do is

try
{
       if (p4 != null)
       {
             p4.RunUnParsed("delete", selectedItemPath);
       }                
}
catch (System.Runtime.InteropServices.COMException ex)
{
        MessageBox.Show(ex.Message);
}

Done!

Categories: C/C++ Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

on line pharmacy @(" prometrium price per pill