Read MS Project files from C#
I have a requirement to read tasks from MS Project file using asp.net and save the tasks in SQL server database. I could do this uising OLEDB and in local machine where MS project is installed. But not able to deply this in the server, cause is MSP is not installed in the server... is it possible to add any DLLs any any other utilities. Please help.
Re: Read MS Project files from C#
Below is the method how I went about reading a Microsoft Project file in C#:
using Microsoft.Office.Interop.MSProject;
using System.Reflection;
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
projectApp.FileCloseAll(PjSaveType.pjDoNotSave);
A pretty simple example, but I could not find a single example of doing this online.
Projectin' Tom Out.
Re: Read MS Project files from C#
Hi JAMES_911,
Very useful your post.
Please, one doubt... when I try to compile I receive this error message:
"The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)"
Is it necessary install a DLL ?
Thanks, best wishes.
Daniel
Re: Read MS Project files from C#
Hi daniel.aquere,
The error that you are getting is mainly due to PIA's (primary interop assemblies) not registered to the GAC for XP or any version of Windows. You just got to add the dlls in the following download or register the dlls through visual studio command prompts. The error is coming because you don't have the proper reference. In this case it very well could be due to differing versions.
Re: Read MS Project files from C#
Hi Janos,
Thanks for response.
Please, where I find the DLL mentioned to install?
Best
Daniel
Re: Read MS Project files from C#
Hi daniel.aquere,
I think that you can use xp PIAs for 2000, check the below link for same:
http://www.microsoft.com/downloads/d...displaylang=en
Re: Read MS Project files from C#
Hi Janos, :notworthy
Thank you very much.
I´m using 2007 version, it´s working very fine.
Best
Daniel