Automating Project Pro to Project Server - Connecting
For many versions now all the Office client applications have supported COM automation. Even through Project wasn't officially in the Office fold till a few versions ago, it too has a robust COM automation model. At times you want to interact with Project via programming, instead of the user interface. And further than that you may want Project Pro to connect to Project Server to do any number of tasks, for example automating the publish procedure. When you look through the help file on Project automation there is one method that is conspicuously missing, connect to Project Server. There is a property that tells you what server you are connected to, but that's no good if you not connected. So the $64,000 question becomes, "How do you connect the Project Server?" The answer is via the command line. The ONLY way to make Project Pro to connect to Project Server is at startup of the application, either UI or automation driven. You need to pass the following parameters:
· /s servername - Server name to connect to.
· /u username - Used to pass Project Server user name, not used for Windows Authentication
· /u password- Used to pass Project Server user name password, not used for Windows Authentication
A point on the parameters above, if you are using Windows authentication, you do not pass username and password, it is implied by your credentials. Programmatically your startup routine, in C#, may look like this.
string fullProgramName = GetWinProjectLocation();
string programArgs = "/s " + PROJECT_SERVER_URL;
if (!m_IntegratedAuth)
{
programArgs += " /u \"" + username + "\" /p \"" + password + "\"";
}
System.Diagnostics.Process.Start(fullProgramName, programArgs);
There are a couple things to point out that are missing from the above snipet. First, what is GetWinProjectLocation? That is a routine I wrote that goes into the registry to determine where Project Pro is installed. I would have put that routine here, but I want to verify it for Project 12 first. So GetWinProjectLocation will be the subject of a later BLOG entry.
Second, and not as apparent, when can I make calls to Project automation? You can NOT immediately start making calls to automation. Even though the automation object is open, the connection to Project Server takes 2-10 seconds (or worse on high latency systems) and you will get automation errors returned if you call before it's ready. The typical thing to do here is put in a delay. I went ahead and built some code for determining when Project is ready for automation commands. That will also be the topic of a future post.
Finally, if Project pro is already open, you are stuck with whatever the connection state is. So you need to detect if Project is open and.... be able to shut it down before starting up. I'll also include this in a future post.
So this turned out to be a start to a few articles on automating Project Pro with Project Server. I look forward to finishing it over the next few weeks.
Comments
- Anonymous
August 22, 2006
I am facing similar issue, i.e. how to find whether the automation server is ready. Do post the methodology to determine whether automation server is ready.