Creating Task Links

Contents
[ Hide Show ]

Task links define relationships between two tasks in a project schedule. Each link connects a predecessor task to a successor task and controls how the tasks are scheduled relative to one another.

Microsoft Project supports four standard link types:

Aspose.Tasks for .NET provides the TaskLink class to create and manage these links programmatically.

To create a task link in Aspose.Tasks:

  1. Use the TaskLink constructor, which accepts three parameters:

    • The predecessor task,
    • The successor task,
    • The link type (TaskLinkType enumeration). The link type parameter is optional; the default is Finish-to-Start (FS).
  2. Add the link to the project’s task links collection.

The example below demonstrates creating a link between two tasks, with Task1 as the predecessor and Task2 as the successor:

1// Create new project and add tasks
2Project project = new Project();
3Task pred = project.RootTask.Children.Add("Task 1");
4Task succ = project.RootTask.Children.Add("Task 2");
5
6// Links tasks
7TaskLink link = project.TaskLinks.Add(pred, succ);

Conclusion

Creating task links is fundamental for defining dependencies in project schedules. Using the TaskLink class and TaskLinkType enumeration in Aspose.Tasks for .NET, developers can programmatically establish and manage task relationships, enabling precise control over project planning and scheduling logic.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.