Adding a New Task with Aspose.Tasks vs VSTO

Add a Task Using VSTO

To add a task using VSTO:

  1. Create a new project in Visual Studio.
  2. In the Solution Explorer, right-click and select Add Reference.
  3. Select the COM components tab, and select Microsoft Project 12.0 Object Library.
  4. Click OK.

This imports the Microsoft.Office.Interop.MSProject namespace at the start of your code. Use the code from the following example to add a new task.

Microsoft.Office.Interop.MSProject.Application projectApplication = new Application();
object missingValue = System.Reflection.Missing.Value;
projectApplication.FileOpenEx(@"C:\Project1.mpp",
    missingValue, missingValue, missingValue, missingValue,
    missingValue, missingValue, missingValue, missingValue,
    missingValue, missingValue, PjPoolOpen.pjPoolReadOnly,
    missingValue, missingValue, missingValue, missingValue,
    missingValue);
Microsoft.Office.Interop.MSProject.Project project = projectApplication.ActiveProject;
Microsoft.Office.Interop.MSProject.Task task;
task = project.Tasks.Add("Task1", 1);
task.Start = "8/23/2012";
task.Duration = 3 * 8 * 60;
task.Text1 = "Task1";
projectApplication.FileCloseAll(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave);

Add a Task Using Aspose.Tasks for .NET

To add tasks to project files using Aspose.Tasks for .NET:

  1. Create a new project in Visual Studio.
  2. In the Solution Explorer, right-click and select Add Reference.
  3. Select .NET tab and select Aspose.Tasks.
  4. Click OK.

This imports the Aspose.Tasks namespace at the start of your code. Use the code from the following example to add a new task.