Creating Task Links
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:
- Finish-to-Start (FS) – Successor starts after predecessor finishes.
- Start-to-Start (SS) – Successor starts when predecessor starts.
- Finish-to-Finish (FF) – Successor finishes when predecessor finishes.
- Start-to-Finish (SF) – Successor finishes when predecessor starts.
Aspose.Tasks for .NET provides the TaskLink class to create and manage these links programmatically.
Creating a Task Link
To create a task link in Aspose.Tasks:
Use the
TaskLinkconstructor, which accepts three parameters:- The predecessor task,
- The successor task,
- The link type (
TaskLinkTypeenumeration). The link type parameter is optional; the default is Finish-to-Start (FS).
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.