Active Directory Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail
How Long For Me
<< Back To All Blogs
Reading a Microsoft Project file (mpp) in C#
Wednesday, June 24th, 2009
I was recently presented with the need to read the tasks from a Microsoft Project file and to my surprise there is not a large number of information on doing so.
There is an open source project on source forge called MPJX which claims to support .NET as well, but upon further investigation I realized that it was actually embedding a virtual Java processor in .NET and then calling
the Java-native version... yuck.
So I decided the way I would go is to use .NET Interop to invoke Microsoft Project and pull the information I required. The only downside to this approach is that you most have Project installed on the box, but for me this was not an issue.
You will need to add a reference to Microsoft Project in your Visual Studio project, and it will be under the COM tab, not under the .NET tab.
So without further ado, here is how I went about reading a Microsoft Project file in C#:
ApplicationClass projectApp = new ApplicationClass();
// Open the file. There are a number of options in this constructor as you can see
projectApp.FileOpen("C:\myfile.mpp", true, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
PjPoolOpen.pjDoNotOpenPool, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
// Get the active project
Project proj = projectApp.ActiveProject;
// Enumerate the tasks
foreach (Task task in proj.Tasks)
string name = task.Name;
// Project stores the number of minutes in a workday, so 8 hours per workday * 60 = 480. 480 is a project "day"
int duration_in_days = Int32.Parse(task.Duration.ToString()) / 480;
DateTime start = DateTime.Parse(task.Start.ToString());
DateTime finish = DateTime.Parse(task.Finish.ToString());
double percent_complete = Double.Parse(task.PercentComplete.ToString());
DateTime actual_finish = DateTime.Parse(task.ActualFinish.ToString());
// Do something with each task here
// Make sure to clean up and close the file
A pretty simple example, but I could not find a single example of doing this online.
Projectin' Tom Out.
Fedora Core 20 and Apache Virtual Host on mounted share
Some Useful Powershell commands for the Linux nerds out there
Awesome .NET 4: Named and Optional Parameters for Classes and Methods
Restoring Specific Documents from a MOSS 2007 Content Database Backup
Cathy said on Thursday, October 24th, 2013 @ 11:54 PM
There is a .NET/C# Library available now known as Aspose.Tasks for .NET for not only reading MS Project Files (MPP/XML) but creating, modifying and converting MPP files to many other formats. Check out this Library to know more its features:
Asit Aithal said on Friday, January 8th, 2010 @ 8:29 AM
Great stuff. How can I iterate thru' all the fields and display the values?
Tom said on Tuesday, November 17th, 2009 @ 12:44 PM
Glad to hear it helped, I myself had quite a tough time finding documentation during the process.
rob said on Tuesday, November 17th, 2009 @ 12:37 PM
Thanks! This saved me a tonne of time. You are correct in that there isn't much documentation out there regarding opening MS Project files using interop.
Tom said on Sunday, October 11th, 2009 @ 6:02 PM
I never had to try using the Interop assembly without Project installed, so I'm not sure. This is probably a possibility but you would have to be careful with licensing. You may also have to fight with a number of system DLL dependencies as I'm sure Project has a number of them if it is anything like the other Office Products.
Hugonne said on Wednesday, October 7th, 2009 @ 3:50 PM
My bad, I just read that indeed you have to have it installed. Too bad. Could there be a way to deploy with just the Interop assembly, so thah Project isn't needed? Thanks.
Hugonne said on Wednesday, October 7th, 2009 @ 3:48 PM
Hey, great article. I have a question though: When this application gets deployed, does the production machine need a copy of Project installed? See, we're developing an utility to load to a Sql Server db Excel and Project files, but we wouldn't like to have Project (or Excel, but that can be solved with ODBC) installed on the production server. Thanks.
Add A Comment
Email Address: (not public, used to send notifications on further comments)
Enter the text above, except for the 1st and last character: