Microsoft Project Data Reading and Writing Summary
Reading and Writing Microsoft Project Data with Aspose.Tasks for .NET
Aspose.Tasks for .NET provides an API for reading and writing Microsoft Project data programmatically. This page summarizes the capabilities of accessing and manipulating project data without having to install Microsoft Project software.
Reading Project Data
Aspose.Tasks allows developers to read project data from various sources:
- Project Files: import MPP, XML, MPT files directly
- Task Information: Access task properties including ID, name, duration, start/end dates, constraints, deadlines and scope
- Resource Data: Retrieve resource information such as availability, cost and assignment
- Calendar Settings: Read working hours, exceptions and calendar hierarchies
- Extended Attributes: Access custom fields and project metadata
- Baselines: Read baseline data for tasks and resources
- Views: Access Gantt chart, task usage and other project views
Writing Project Data
The API supports comprehensive data writing capabilities:
- Create Project: Create new project files from scratch
- Task Management: Add, modify, or delete tasks with their properties
- Resource Processing: Create and modify resources and their assignments
- Schedule Calculation: Recalculate project schedules after processing modification data
- Format Conversion: Save projects in various formats, including MPP, XML, PDF
- View Settings: Change and save project views with formatting options
Data Management Scenarios
Common scenarios for working with Microsoft Project data:
- Read project task hierarchies and dependencies
- Analyze critical paths and task constraints
- Manage resource allocation and workload
- Update project percent complete and percent complete
- Manipulate project baselines for variance analysis
- Change calendars and work time settings
- Convert between different versions of Microsoft Project
Code Examples
Below are basic examples of reading and writing Microsoft Project data:
1 // Reading a project file
2 Project project = new Project("Project.mpp");
3
4 // Accessing task data
5 foreach (Task task in project.EnumerateAllChildTasks())
6 {
7 Console.WriteLine($"Task: {task.Name}, Duration: {task.Duration}");
8
9 // Access assignments
10 foreach (ResourceAssignment assignment in task.Assignments)
11 {
12 Console.WriteLine($"Assigned to: {assignment.Resource.Name}, Work: {assignment.Work}");
13 }
14 }
15
16 // Writing project data
17 Project newProject = new Project();
18 Task task1 = newProject.RootTask.Children.Add("Task 1");
19 task1.Duration = newProject.GetDuration(2, TimeUnitType.Day);
20 task1.Start = new DateTime(2023, 1, 10);
21 task1.Finish = new DateTime(2023, 1, 12);
22
23 // Save the project
24 newProject.Save("NewProject.mpp", SaveFileFormat.MPP);