Microsoft Project is a popular project management software that makes it easier for project managers to efficiently manage the projects. It lets the managers create tasks and resources, assign tasks to resources, track the project’s progress, manage the budget, and perform other project-related operations. In order to create and manage MS Project files programmatically, Microsoft provides MS Office Automation. However, along with other deficiencies, it requires you to install MS Office. To fill this gap, Aspose jumps in to provide you with an MS Project automation solution for .NET applications as 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. In addition, it offers various features to work with tasks, resources, and calendars. In this article, I’ll show you how to use Aspose.Tasks for .NET to create MS Project files and work with tasks and resources using C#. The rest of the article is divided into the following sections.

Create MS Project Files using C#

MPP is the proprietary file format of Microsoft which is used for MS Project files. However, you can also keep project data in XML files for sharing it among different applications. Creating a new project from scratch is a simple task and can be done using the following steps:

The following code samples show 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#

The empty MS Project file is useless without tasks and resources. So let’s see how to create and add tasks to a project. A task could be a single task or summary task containing a group of subtasks in it. The following are the steps to add tasks to an MS Project file.

  • Create and initialize the Project object.
  • Add a new summary task to the project’s Tasks collection using Project.RootTask.Children.Add(string) method.
  • Add a subtask to the summary task using Task.Children.Add(string) method.
  • Save the project using Project.Save() method.

The following code sample shows how to create and add tasks to MS Project files using C#.

The following code sample shows how to set different properties of the tasks such as duration, start date/time, etc.

Add Resources to MS Project Files using C#

Resources are the entities that are supposed to perform the tasks in a project. Hence, a project would not be possible without the resources to work on it. So let’s check out how to create and add resources to a project. The following are the steps to add resources to an MS Project file.

  • Create a new project using the Project class.
  • Add a new resource to the project’s Resources collection using Project.Resources.Add(string) method.
  • Save the project using Project.Save() method.

The following code sample shows how to add resources to an MS Project file using C#.

The following code sample sets the properties of a resource such as a start date/time, type, etc.

Assign Tasks to Resource in a Project using C#

Once you have completed adding tasks and resources in the project, you can specify which task is to be performed by which resource. Thus, you will assign the task(s) to each resource. The following are the steps to assign tasks to resources in a Project.

  • Create or load a project using Project class.
  • Add new resources to the project and set their properties such as date format, start date, etc.
  • Add new tasks to the project and set their properties such as start date/time, duration, and etc.
  • Perform tasks assignment by adding the task and its respective resource to Project.ResourceAssignments collection.
  • Save the project using Project.Save() method.

The following is the complete code sample of how to create and assign tasks to resources in an MS Project file.

Add Calendar to a Project using C#

The calendars are also one of the main entities of the projects which are used to define the project’s schedule. The calendar makes it possible for the project managers to create a timeline for a project. The following are the steps to add a calendar to a project.

The following code sample shows how to add 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. You can get one from here.

See Also