Manage Project Outline Codes in Aspose.Tasks for .NET

Introduction

In this tutorial, we will explore how to manage Microsoft Project outline codes using Aspose.Tasks for .NET. Outline codes are custom fields in Microsoft Project that allow users to categorize and organize tasks according to specific criteria. Aspose.Tasks simplifies the process of reading and manipulating these outline codes programmatically.

Prerequisites

Before we begin, ensure you have the following:

  1. Aspose.Tasks for .NET Library: Download and install the Aspose.Tasks for .NET library from the website.
  2. Development Environment: Set up a suitable development environment for .NET programming, such as Visual Studio.
  3. Basic Knowledge of C#: Familiarity with C# programming language will be beneficial for understanding the code examples.

Importing Namespaces

To get started, you need to import the necessary namespaces into your C# project. This allows you to access the classes and methods provided by the Aspose.Tasks library.

  1. Open Visual Studio: Launch your Visual Studio IDE.
  2. Create a New Project: Start a new C# project or open an existing one where you intend to use Aspose.Tasks.
  3. Add Aspose.Tasks Reference: Right-click on your project in the Solution Explorer, select “Manage NuGet Packages”, search for “Aspose.Tasks”, and install the latest version.
  4. Import Aspose.Tasks Namespace: At the top of your C# file, add the following using directive:
using Aspose.Tasks;
using System;

Step 1: Define Document Directory

First, set the path to the directory containing your MS Project file.

String DataDir = "Your Document Directory";

Replace "Your Document Directory" with the actual path to your project file.

Step 2: Load the Project File

Instantiate a new Project object by loading the MS Project file.

var project = new Project(DataDir + "OutlineValues2010.mpp");

This initializes the project object with the specified file.

Step 3: Read Outline Codes

Iterate through all tasks in the project and retrieve their outline codes.

foreach (var task in project.RootTask.SelectAllChildTasks())
{
    if (task.OutlineCodes.Count <= 0)
    {
        continue;
    }
    Console.WriteLine("Print outline codes of the task: " + task.Get(Tsk.Name));
    foreach (var value in task.OutlineCodes)
    {
        Console.WriteLine("  Field Id: " + value.FieldId);
        Console.WriteLine("  Value Guid: " + value.ValueGuid);
        Console.WriteLine("  Value Id: " + value.ValueId);
    }
}

This code snippet loops through each task, checks if it has outline codes, and prints out details such as Field Id, Value Guid, and Value Id for each outline code associated with the task.

Conclusion

In conclusion, Aspose.Tasks for .NET provides powerful capabilities for managing Microsoft Project outline codes programmatically. By following the steps outlined in this tutorial, you can efficiently read and manipulate outline codes in your MS Project files using C#.

FAQ’s

Q: Can I modify outline codes using Aspose.Tasks?

A: Yes, you can modify outline codes programmatically using Aspose.Tasks for .NET. Simply access the outline codes of tasks and update their values as needed.

Q: Is Aspose.Tasks compatible with all versions of Microsoft Project?

A: Aspose.Tasks supports a wide range of Microsoft Project versions, including 2003, 2007, 2010, 2013, 2016, and 2019.

Q: Does Aspose.Tasks require a license for commercial use?

A: Yes, a valid license is required for commercial use of Aspose.Tasks. You can obtain a license from the Aspose website.

Q: Can I try Aspose.Tasks before purchasing?

A: Yes, you can download a free trial version of Aspose.Tasks from the website to evaluate its features and capabilities.

Q: Where can I get support for Aspose.Tasks?

A: You can get support for Aspose.Tasks by visiting the forum at Aspose.Tasks Forum.## Complete Source Code