A Generic Library For Accessing and Creating Microsoft Project Plan File

Introduction

 
In a project, if you need to extract data from Excel then you have many options irrespective of technology. But if you have a requirement to retrieve data from a Microsoft Project Plan (MPP) file, you have a limited number of options.
 
First, you can use the Microsoft Project Exchange (MPXJ) open-source library to retrieve data from an MPP file. But the problem is that it is coded in Java and the .Net version just embeds a virtual Java processor and then calls the Java-native version. It involves performance overhead.
 
Secondly, you can use the Interop library provided in .Net. Using this library, you can access an MPP file but is very complex and low-level. Programming directly against Interop has been an issue with developers.
 
We came up with a generalized library keeping in mind the structure and fields of an MPP file. It provides you a direct mapping with built-in fields of an MPP file in an exact manner. For example, tasks in a project may have subtasks, but when you directly read it using Interop even subtasks will be considered as separate tasks. Then the essence of an MPP file gets lost and rather it looks like an Excel file.
 
 
Fig 1.0 Structure of MILE
 
We have kept intact the extensibility of the Interop library and allowed the user to access and create an MPP file in a generalized manner keeping the essence of a project file intact.
 
 
Fig 1.1 Class Specifications
 
Extensions
  • Disconnected architecture
  • LINQ extensibility
  • Generate MPP file in a generalized manner
  • Accessing data from project file in its essence
  • Refinement- Child tasks
  • Secure for web application
Prerequisites
 
Microsoft Project should be installed on your machine.
 
In order to use this library, you can use the following procedure.
  1. Add a reference to the provided DLL.
  2. Import Abhi.MILE.
  3. Create a List object of type MppTask and a reference variable of type MPPProject.
    1. // Creating a List variable of type MppTask  
    2. List<MppTask> lsMppTasks;  
    3. // Creating a reference variable of type MPPProject  
    4. MPPProject project; 
  4. Declare a string variable "path" to store the location of the MPP file and store the path in it.
    1. // Creating a string variable to store the path of Mpp file  
    2. String path;  
    3. path=”Your path here”; 
  5. After storing the path, just instantiate an object of MPPProject Class as per the class definition.
    1. // Creating an object of type MPPProject  
    2. project = new MPPProject(path); 
  6. Retrieve all tasks present in the mpp file through the object created in the last step. Invoke the GetAllTasks method and store all tasks present in a list variable created in Step 3.
    1. // Invoking GetAllTasks() Method to retrieve all tasks present in MPP file  
    2. lsMppTasks = project.GetAllTasks(); 
  7. Now you have a project object that contains all tasks, subtasks, and resources present in the Mpp file. Using a List variable we can access subtasks and all other fields or properties of a specific task as shown below:
    1. // Retrieving Name of the first task  
    2. Firsttask.text=lsMpptasks[0].Name;  
    3. // Retrieving the name of the First child of the first task  
    4. FirstChildOfFirstTask.text= lsMpptasks[0].ChildTasks[0].Name;  
    5. // Retrieving the start date of the First child of the first task  
    6. ChildTaskStartDate.Text = lsMpptasks [0].ChildTasks[0].StartDate.ToString();  
    7. // Retrieving the name of the second child of the first task  
    8. SecondChildOfFirstTask.Text = lsMpptasks [0].ChildTasks[1].Name;  
    Now the lsMppTask object can be used to access the entire information present in the MPP file using methods as shown in the Class specification. In this way, the library can be used for accessing all information present in an MPP file.
     
  8. Similarly, we can create an MPP File by creating a list of MppTasks and pass them into the CreateMppFile method of the MppProject class.
    1. // Creating a List variable of type MppTask to store task information  
    2. List<MppTask> lsMppTasks;  
    3. //Creating a MppTask object and initializing some properties  
    4. MppTask task1=new MppTask();  
    5. task1.Name=”Task1”;  
    6. task1.StartDate=”30/09/2012”;  
    7. task1.FinishDate=”10/11/2012”;  
    8. //Creating another MppTask object and initializing some properties  
    9. task2.StartDate=”12/09/2012”;  
    10. task2.FinishDate=”01/11/2012”;  
    11. //Adding both Mpptask objects to List object  
    12. lsMppTasks.Add(task1);  
    13. lsMppTasks.Add(task2);  
    14. /*Invoking CreateMppFile Method of project class to create a Mpp file with all information present in List object */  
    15. project .CreateMppFile(lsMppTasks,”D:/My_MppFile.mpp”); 
For all remaining properties and methods, kindly refer to the class specification given before.
 
Reference(s)