
Microsoft Project is popular project‑management software that helps managers efficiently handle projects. It lets managers create tasks and resources, assign tasks, track progress, manage budgets, and perform other project‑related operations. To create and manage MS Project files programmatically, Microsoft provides MS Office Automation. However, it has other deficiencies and requires MS Office installation. Aspose fills this gap with an MS Project automation solution for .NET applications called Aspose.Tasks for .NET.
Aspose.Tasks for .NET is a feature‑rich API that lets you create MS Project files (.mpp/.xml) programmatically using C# or VB.NET. It also provides extensive features for working with tasks, resources, and calendars. In this article, I’ll show how to use Aspose.Tasks for .NET to create MS Project files and manage tasks and resources with C#. The article is organized into the following sections.
- Create an MS Project file from scratch using C#
- Add tasks to a Project
- Add resources to a Project
- Assign tasks to resources in a Project
- Add calendars to a Project
Create MS Project Files using C#
MPP is Microsoft’s proprietary format for MS Project files. You can also store project data in XML files for cross‑application sharing. Creating a new project from scratch is straightforward:
- Create an instance of the Project class.
- Save the file with Project.Save(string, SaveFileFormat).
The code samples below demonstrate how to create MS Project files using C#.
Save MS Project Files as MPP
Save MS Project Files as XML
Add Tasks to MS Project Files using C#
An empty MS Project file is useless without tasks and resources. Below are the steps to add tasks:
- Create and initialize the Project object.
- Add a summary task to the project’s Tasks collection with
Project.RootTask.Children.Add(string). - Add a subtask to the summary task using
Task.Children.Add(string). - Save the project with Project.Save().
The sample code creates and adds tasks to MS Project files using C#.
The next sample sets task properties such as duration and start date/time.
Add Resources to MS Project Files using C#
Resources perform the tasks in a project, so they are essential. Follow these steps to add resources:
- Create a new project with the Project class.
- Add a resource to the project’s Resources collection using
Project.Resources.Add(string). - Save the project with Project.Save().
The code sample adds resources to an MS Project file using C#.
The following sample sets resource properties such as start date and type.
Assign Tasks to Resource in a Project using C#
After adding tasks and resources, assign each task to a resource. Steps:
- Create or load a project with the Project class.
- Add resources and set their properties (date format, start date, etc.).
- Add tasks and set their properties (start date/time, duration, etc.).
- Assign tasks by adding entries to the Project.ResourceAssignments collection.
- Save the project with Project.Save().
The complete code sample shows how to create a project and assign tasks to resources.
Add Calendar to a Project using C#
Calendars define a project’s schedule and timeline. To add a calendar:
- Create or load a project with the Project class.
- Add a new Calendar to the Project.Calendars collection.
- Define the schedule using the Calendar object.
- Save the project.
The code sample adds a calendar to a project using C#.
Download or Install
You can download Aspose.Tasks for .NET DLL or install it in your project using NuGet.
Try Aspose.Tasks for .NET for Free
Aspose offers a free temporary license to try its products without trial limitations. Get one from here.