Opening an existing mpp file in a C# windows application

S

Strider

Hi

I need to load an existing mpp file in a C# windows application.
I'm using Microsft 9.0 Object Library.
The appliaction would allow a user to browse for an mpp file and then load it.

When I try to create an object of the MSProject.ProjectClass class , I get
the following exception :
An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in sample2.exe
Additional information: COM object with CLSID
{1019A320-508A-11CF-A49D-00AA00574C74} is either not valid or not registered

Is there a way to load an mpp file programatically by specifying a path for
the file ?

Thanks
 
R

Rod Gill

Hi,

You need to create a reference to the Project object library, then open the
Project application. This will open as a separate window, not part of your
app. You can then use FileOpen to open the file your user browsed for.
 
S

Strider

Hi Rod
Thanks for the reply , but I'm not sure I competely understood what you just
said.
This application that I 'm workin on , aims at exporting mpp files to SQL
Sever without using either MS Project or Project Server.
I'm only allowed to use the Project Object Library.
As you suggested , is there a way to open the project application using the
Project Object library ( considering that MS project is not installed on the
machine) ?
Most importantly, I need to open an mpp file so as to populate the
"ProjectClass"
object provided in the Project Object library and then later save to the
database .
Could you please suggest a way to do this .

Thanks
 
R

Rod Gill

That I'm aware of, the Project Object library only works with the
application, so you have to open the application to get it to work. I've
never heard of any other way.

There is a third method: you can use OLEDB to read directly from a .mpp
file. However, the OLEDB license requires you to have Project installed on
the PC using it (I think). See pjoledb.htm in one of Project's program
folders for details of how to use it. It's fast and does not require the
file to be opened.

The only other alternative is to have users save their projects to SQL
Server rather than .mpp files.
 
S

Strider

Thanks Rod.
Currently there's Project 2000 installed on my machine and i found a file
named ole_db.htm which does provide details on how to read an mpp file using
oledb.
Is there a way to save an mpp file to sql server using oledb as well.
 
R

Rod Gill

No. You use oledb to read the data, then your code needs to save the data
read to SQL Server. If you only have 2000, then OLEDB is somewhat limited.
To read all data, you need Project 2003. For example 2000 has no timephased
data. 2002 does not manage day by day timephased data correctly.
 
S

Strider

Hey , I think I've managed to work something out.
I was able to load a mpp file using the ApplicationClass.FileOpen() ,
provided in the project object library.
With this , the project can be directly exported to SQL server by appending
something like a DSN on the fly .Here's some code in c# :

string DSN = "<{SQLServer};Driver=SQL Server;"
+ "Server=MyServer;Database=MyDatabase;UID=sa;PWD=
;"+ "WSID=APC;APP="+projectApp.Name+@";Language=English;Trusted_Connection=Yes>\";

bool isExported = ApplicationClass.FileSaveAs ( DSN +
ApplicationClass.ActiveProject.Title , PjFileFormat.pjMPP ,
System.Type.Missing , System.Type.Missing , System.Type.Missing ,
System.Type.Missing , System.Type.Missing , "sa" , "" , "MSProject.odbc" ,
System.Type.Missing , System.Type.Missing , System.Type.Missing , false ,
System.Type.Missing , System.Type.Missing , System.Type.Missing )

This codes exports the mpp file to SQL Server 2000.
 
R

Rod Gill

Looks like you've instantiated a hidden copy of the application
(ApplicationClass and then open and saved the project. That's the method I
first suggested. Interestingly enough the VB code for this is:

ProjApp.FileSaveAs Name:="<ProjectDatabase>\Project Title", UserId:="myID",
DatabasePassWord:="", FormatID:="ProjectDSN.ODBC"

Much easier to read!!

Sorry I was slow getting the right answer, I'm not a C# person. My last C
was embedded on 8088 CPU's many years ago!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top