Task's General Properties

Tasks can be identified by a number of general properties, such as name, ID, start and finish date. Aspose.Tasks can be used to get and set task properties when working with projects.

Overview

The static class Tsk contains all the properties related to a Task and can get or set using the Get and Set methods exposed by Task class. Some of the commonly used properties are as follow:

To view a task’s general properties in Microsoft Project:

  1. Open a project.
  2. On the View menu, select More Views and then Task Entry to open the task entry form.
  3. From the Insert menu, select Column and add the ID and Unique ID.

Setting General Properties

The code example given below demonstrates how to set general properties.

1// Create project instance
2System::SharedPtr<Project> project = System::MakeObject<Project>();
3    
4// Add task and set task properties
5System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"Task1");
6task->Set(Tsk::Start(), project->get_RootTask()->Get<System::DateTime>(Tsk::Start()).AddDays(1));
7task->Set<System::String>(Tsk::Name(), u"new name");

Getting General Properties

Get a task’s properties by traversing the children of the project’s RootTask property.

 1// The path to the documents directory.
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3    
 4// Create project instance
 5System::SharedPtr<Project> prj = System::MakeObject<Project>(dataDir + u"ReadTaskProperties.mpp");
 6    
 7// Create a ChildTasksCollector instance
 8System::SharedPtr<ChildTasksCollector> collector = System::MakeObject<ChildTasksCollector>();
 9    
10// Collect all the tasks from RootTask using TaskUtils
11TaskUtils::Apply(prj->get_RootTask(), collector, 0);
12    
13// Parse through all the collected tasks
14    
15{
16    auto tsk_enumerator = (collector->get_Tasks())->GetEnumerator();
17    decltype(tsk_enumerator->get_Current()) tsk;
18    while (tsk_enumerator->MoveNext() && (tsk = tsk_enumerator->get_Current(), true))
19    {
20        System::Console::WriteLine(u"Task Id: {0}", System::ObjectExt::Box<int32_t>(tsk->Get<int32_t>(Tsk::Id())));
21        System::Console::WriteLine(u"Task Uid: {0}", System::ObjectExt::Box<int32_t>(tsk->Get<int32_t>(Tsk::Uid())));
22        System::Console::WriteLine(u"Task Name: {0}", System::ObjectExt::Box<System::String>(tsk->Get(Tsk::Name())));
23        System::Console::WriteLine(u"Task Start: {0}", System::ObjectExt::Box<System::DateTime>(tsk->Get<System::DateTime>(Tsk::Start())));
24        System::Console::WriteLine(u"Task Finish: {0}", System::ObjectExt::Box<System::DateTime>(tsk->Get<System::DateTime>(Tsk::Finish())));
25    }
26}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.