Creating Tasks

A project is essentially composed of multiple tasks. Each task represents a unit of work that must be completed for the overall project to succeed. When working with project files, adding tasks is a fundamental activity.

Tasks may:

With Aspose.Tasks for .NET, developers can create tasks programmatically and specify their name, hierarchy, or duration right at the time of creation.

Creating Tasks

The Task class exposes the Add method, which allows adding a task to a project’s RootTask or as a child of another task. The default constructor creates a Task instance without requiring any parameters. Developers can then configure its properties such as Name, Duration, or Start.

Example: Adding a New Task

The following code sample demonstrates how to create new tasks and add them to a project:

1Project project = new Project();
2
3// Add task, sub task and save project
4Task task = project.RootTask.Children.Add("Summary1");
5Task subtask = task.Children.Add("Subtask1");
6project.Save("CreateTasks_out.xml", SaveFileFormat.XML);

Key Notes

FAQ

Q: Can I assign a duration when creating a task?

Q: Can tasks be created without linking to others?

Q: Does creating a task automatically set its start and finish dates?

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.