Open Source .NET Project Management API to Handle Projects in Redmine

Leading C# .NET Project Management Library allows Developers to Create, Eead, Manipulate and Convert Project Files to Other Formats like MPP, MPT, XML, XER, PMXML, and many more.

What is MPXJ.NET?

Managing project data often means wrestling with a multitude of file formats from tools like Microsoft Project, Primavera P6, and others. If you're a .NET developer looking to read, write, and manipulate project data programmatically without being locked into a single platform, MPXJ.NET is the powerful, open source library you've been searching for. The library has included several important features for working with project management files, such as create new projects, reading existing project files, converting between formats, manipulating schedule data, working with resources and assignments, programmatically.

MPXJ.NET is an open-source .NET wrapper around the Java library MPXJ (Managed by Jon Iles). It allows .NET developers—C#, VB.NET, etc.—to read, write and manipulate project-schedule files using idiomatic C# types and conventions. MPXJ library supports many schedule and project formats such as MPP, MPX, MSPDI XML, XER, P6 databases, Planner XML, etc. Although MPXJ is originally Java-based, MPXJ.Net wraps it and presents C# conventions (properties rather than Java getters/setters; .NET naming conventions) so it feels natural in .NET code. Whether you are aggregating data for an enterprise portfolio, performing quality checks on schedules, or building a bridge between your CRM and your PMO's tools, MPXJ.Net provides the reliable, high-performance foundation you need.

Previous Next

Getting Started with MPXJ.NET

The recommend way to install MPXJ.NET is via NuGet. Please use the following commands for a smooth installation.

Install MPXJ.NET via NuGet

NuGet\Install-Package MPXJ.Net -Version 14.5.2

You can download the directly from GitHub page

Create and Manipulate Projects via .NET

The open source MPXJ.NET has provide several important features for handling project files inside .NET applications. Beyond reading, you can create new project files from scratch: define project properties (title, author, start date), add calendars and exceptions, add tasks (with durations, start dates, numeric fields), add resources and assignments, create dependencies (task A precedes task B), and then save to a file format (e.g., MSPDI or MPX) that can be opened by MS Project or other tools. Here is a simple example that demonstrates, how to create a new project inside .NET applications.

How to Create a New Project and Write It in XML Format via .NET Library?

using Net.Sf.Mpxj;
using Net.Sf.Mpxj.Write;
using System;

// Create a new, empty project file
ProjectFile project = new ProjectFile();

// Set basic project properties
project.Name = "My New MPXJ-Generated Project";
project.StartDate = DateTime.Now;

// Add tasks
Task task1 = project.AddTask();
task1.Name = "Task 1";
task1.Duration = project.GetDuration(8, TimeUnit.Hours); // 1 day
task1.Start = DateTime.Now;

Task task2 = project.AddTask();
task2.Name = "Task 2 (Child of Task 1)";
task2.Duration = project.GetDuration(16, TimeUnit.Hours); // 2 days
task2.Start = DateTime.Now.AddDays(1);
// Make task2 a child of task1 by setting the outline level
task2.OutlineLevel = 1;

// Create a writer for the desired output format
ProjectWriter writer = new MicrosoftProjectWriter();

try
{
    // Write the project to an XML file (compatible with MS Project)
    writer.Write(project, "C:\\Projects\\MyNewProject.xml");
    Console.WriteLine("Project file written successfully!");
}
catch (Exception ex)
{
    Console.WriteLine($"Failed to write file: {ex.Message}");
}

Universal Project File Reading via C#

The primary strength of MPXJ.NET library is its ability to load and read a vast number of formats with a simple, consistent API. The library has included support for automatically detect the file format based on the file's extension and content. The Read method returns a ProjectFile object, which is the root container for all other project entities like tasks, resources, and assignments. This simple pattern works identically for an XER file, an XML file, or any other supported format The following example shows how to perform it with ease.

How to Load and Read an MPP Project File via .NET API?

using Net.Sf.Mpxj;
using Net.Sf.Mpxj.Read;

// Create a ProjectReader instance.
// The UniversalProjectReader intelligently determines the file type.
ProjectReader reader = new UniversalProjectReader();

try
{
    // Read the project file. This one line of code is all you need.
    ProjectFile project = reader.Read("C:\\Projects\\MySchedule.mpp");

    // Now you have access to all project data!
    Console.WriteLine($"Project Name: {project.Name}");
    Console.WriteLine($"Start Date: {project.StartDate}");
}
catch (Exception ex)
{
    Console.WriteLine($"Failed to read file: {ex.Message}");
}

           

Project Files Conversion via .NET API

The open source MPXJ.NET has include complete support for converting project files into other support file formats inside .NET applications. Because of its multi-format capacity, MPXJ.NET is often used to convert project files from one format to another inside .NET applications. For instance: read .MPP file, then write to .MPX or .MSPDI or even XER/PMXML (depending on support). The README provides example of converting.

How to Read and Convert Project File inside .NET Apps?

using System;
using MPXJ.Net;

namespace ConvertProject
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = "LegacyProject.mpp";
            string output = "ConvertedProject.mpx";

            // Read using universal reader
            var proj = new UniversalProjectReader().Read(input);

            // Write using universal writer to MPX format
            new UniversalProjectWriter(FileFormat.MPX).Write(proj, output);

            Console.WriteLine($"Converted {input} → {output}");
        }
    }
}
           

Accessing Project Tasks and Hierarchy

Projects are made of tasks, and MPXJ.NET allows you to traverse the entire Work Breakdown Structure (WBS). The library supports various features for handing projects tasks and data, such as listing of all tasks in the project, view tasks summary, tasks Duration, Start and Finish of a task, Percentage0Complete of a tasks, and many more. The following example demonstrates how developers can iterate through all tasks using .NET commands.

How to Iterate Through All Project’s Tasks via C# API?

using Net.Sf.Mpxj;

// ... (Assume 'project' is a loaded ProjectFile object)

Console.WriteLine("Tasks in the project:");
foreach (Task task in project.Tasks)
{
    // Calculate the indentation for a hierarchical view
    string indent = new string(' ', task.OutlineLevel * 2);

    Console.WriteLine($"{indent}ID: {task.ID}, Name: {task.Name}, " +
                      $"Duration: {task.Duration}, " +
                      $"Start: {task.Start}, Finish: {task.Finish}");

    // Access specific properties
    if (task.PercentageComplete != null && task.PercentageComplete > 0)
    {
        Console.WriteLine($"{indent}  -> % Complete: {task.PercentageComplete}");
    }
}