Jump to content

p4api simplest of examples

p4api c# .net simple

  • Please log in to reply
1 reply to this topic

#1 SullyMonster



  • Members
  • Pip
  • 1 posts

Posted 26 June 2017 - 05:08 PM

Hi All,

I'm hoping someone can help - I've spent a day of work looking at all online resources, examples and blogs trying to find an answer.

I'm trying with p4api / .net to do the following actions

* Connect to perforce server
* Edit a single file in the repository
* Update that single file with changes from local file on client

My connection code

// connect to the server
			 _connected = _connection.Connect(null);
			 _client = _repository.GetClient("main_ws");
			 _client.OwnerName = "bunga";
			 _client.Description = "client for main dev";
			 _repository.CreateClient(_client, null);
			 _repository.Connection.Client = _repository.UpdateClient(_client);
		 catch (Exception e)
			 _logger.Log(LogEntryType.Error, string.Format("Error occurred connecting to {0} : {1}", _credentials.URI, e.Message));			

Seems OK, I now specify depot file to edit, and equivalent local client file

if ((_repository != null) && (_repository.Connection.Status == ConnectionStatus.Connected))
				 FileSpec editFiles = new FileSpec
						 DepotPath = new DepotPath(depotPath),
						 ClientPath = new ClientPath(fileName),
				 _client.EditFiles(null, editFiles);
				 _client.SubmitFiles(null, editFiles);

the edit doesn't throw, but the SubmitFiles reports "{"No files to submit from the default changelist.\n"}
Also I don't see the edit in p4v UI after the edit step, which was what I was expecting.

I've tried

* Specifying a new changelist, then adding the files to the changelist by specifying ChangeList ID - didn't work either
* Every combination of the above that I can think of with edit and submit switches

Please, is there some simple example that walks through the above step by step?

Am I doing something incredibly stupid?

#2 p4bill


    Advanced Member

  • Members
  • PipPipPip
  • 217 posts

Posted 29 June 2017 - 01:41 PM

It looks like you might need to sync the file(s) first. If that is a new client, the files are not synced to your client (workspace).

Perforce will not return an error on .EditFiles if the files are not synced. A warning is returned: "file(s) not on client.", and that is why edit does not throw.

If you changed the edit line to:

IList<FileSpec> results = _client.EditFiles(null, editFiles);

you will see that results are null, if the edit had succeeded you'd get a list of FileSpecs for the files that were opened for edit.

I think adding this line before the edit will fix things:

_client.SyncFiles(null, editFiles);

Also tagged with one or more of these keywords: p4api, c#, .net, simple

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users