Creating Resources in VSTO and Aspose.Tasks
Code Examples
VSTO
Below is code sample to create resource in project.
1string filename = @"E:\Aspose\Aspose Vs VSTO\Aspose.Tasks VS VSTO Projects\Sample Files\MyProject.mpp";
2
3object missingValue = System.Reflection.Missing.Value;
4
5Application.FileOpenEx(filename,
6
7 missingValue, missingValue, missingValue, missingValue,
8
9 missingValue, missingValue, missingValue, missingValue,
10
11 missingValue, missingValue, PjPoolOpen.pjPoolReadOnly,
12
13 missingValue, missingValue, missingValue, missingValue,
14
15 missingValue);
16
17Project project = Application.ActiveProject;
18
19project.Resources.Add("Material");
20
21project.Resources.Add("Work");
This code example demonstrates how to create resources in a Microsoft Project file using VSTO (Visual Studio Tools for Office) and the Microsoft Project Interop API. It opens an existing .mpp file (MyProject.mpp) using FileOpenEx, passing Missing.Value for optional parameters and specifying that the file should be opened in read-only pool mode. Once the file is loaded, it accesses the active project through Application.ActiveProject. Two new resources are then added to the project: one of type “Material” and another of type “Work”, using the Resources.Add() method. This approach requires Microsoft Project to be installed on the host machine and is suitable for developers automating tasks directly inside the Office environment. It offers tight integration with the Microsoft Project application but is limited to Windows and desktop-based automation scenarios.
Aspose.Tasks
The Resource class allows to add a new resource to the project.
1Project project = new Project("MyProject.mpp");
2
3project.Resources.Add(new Resource("Material"));
4
5project.Resources.Add(new Resource("Cost"));
This code snippet demonstrates how to load a Microsoft Project file and add new resources using Aspose.Tasks for .NET. It initializes a Project
object from an existing MPP file named MyProject.mpp. Then, it adds two resources to the project: one of type “Material” and another of type “Cost”. These resources can be later assigned to tasks as needed. The Resource
constructor creates resource entries with specified names.