Work with Task Priorities

A task’s priority helps Microsoft Project with automatic resource levelling (a process of fixing conflicts when a resource is over-allocated). In Microsoft Project, it is possible to assign priority values between 0 and 1000 (where 0 is the lowest priority). By default, tasks are assigned the value 500.

Working with Priorities

The priorities associated with a class are handled through the Priority property exposed by the Tsk class.

Priorities in Microsoft Project

To check a task’s priority in Microsoft Project one need to double-click a task in the Task Entry form:

Task priority in Microsoft Project

viewing task priorities

Getting a Task’s Priority

The code example given below demonstrates how to get a task’s priority and write it to a console window using Aspose.Tasks.

 1// Read project from file stream
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3System::SharedPtr<System::IO::FileStream> fs = System::MakeObject<System::IO::FileStream>(dataDir + u"TaskPriority.mpp", System::IO::FileMode::Open);
 4System::SharedPtr<Project> prj = System::MakeObject<Project>(fs);
 5fs->Close();
 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// Display Priorities for all tasks
14    
15{
16    auto tsk1_enumerator = (collector->get_Tasks())->GetEnumerator();
17    decltype(tsk1_enumerator->get_Current()) tsk1;
18    while (tsk1_enumerator->MoveNext() && (tsk1 = tsk1_enumerator->get_Current(), true))
19    {
20        System::Console::WriteLine(tsk1->Get(Tsk::Name()) + u" - Priority : " + System::Convert::ToString(tsk1->Get<int32_t>(Tsk::Priority())));
21    }
22}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.