Is it possible to read Primavera activity codes from a .xer file using .NET aspose.tasks?
Yes, it is possible to read Primavera activity codes from a .xer file using Aspose.Tasks for .NET. To do this, you will need to follow a series of steps to set up your environment and read the data from the file.
Here’s a brief outline of the process:
-
Install Aspose.Tasks for .NET: Ensure that you have the Aspose.Tasks library installed in your .NET project. You can download it from the Aspose website.
-
Import Necessary Namespaces: Make sure to include the required namespaces in your C# code.
-
Define the Document Directory: Specify the path where your Primavera file (.xer) is located.
-
Create PrimaveraReadOptions Object: Instantiate a
PrimaveraReadOptions
object to configure any specific options for reading the Primavera data. -
Set Project UID (if needed): If you want to retrieve a project with a specific UID, set the
ProjectUid
property. -
Read the Primavera Data: Use the
Project
class constructor to read the Primavera data by providing the path to the .xer file and thePrimaveraReadOptions
object. -
Access Activity Codes: Once the project is loaded, you can access the activity codes through the project’s tasks.
Here is a sample code snippet to illustrate how you can read activity codes from a .xer file:
using Aspose.Tasks;
using Aspose.Tasks.Saving;
// Define the path to the Primavera file
string filePath = "path/to/your/file.xer";
// Create PrimaveraReadOptions
PrimaveraReadOptions options = new PrimaveraReadOptions();
// Load the Primavera project
Project project = new Project(filePath, options);
// Iterate through tasks to access activity codes
foreach (Task task in project.RootTask.Children)
{
Console.WriteLine($"Task Name: {task.Get(Tsk.Name)}");
Console.WriteLine($"Activity Code: {task.Get(Tsk.Code)}");
}
This code will read the specified .xer file and print out the names and activity codes of the tasks contained within it.
By following these steps, you should be able to successfully read Primavera activity codes using Aspose.Tasks for .NET. If you have any further questions or need additional assistance, feel free to ask!
Sources:
[1]: Reading MS Project Primavera Data with Aspose.Tasks
@Herrington ,
when project is read from XER or Primavera XML format, activity codes are mapped to outline codes:
var project = new Project("example.xer");
foreach (var code in project.OutlineCodes)
{
Console.WriteLine("Outline code: {0}", code.Alias);
foreach (var v in code.Values)
{
Console.WriteLine(" {0} - {1}", v.Description, v.Value);
}
}