Retrieve all the Task Items in a Project
IEnumerable<TaskProjectItem> taskItems = Project.Current.GetItems<TaskProjectItem>();
foreach (var item in taskItems)
{
// do something
}
Open a Project Task Item
// get the first project task item
var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();
// if there isn't a project task item, return
if (taskItem == null)
return;
try
{
// Open it
//At 2.x -
//System.Guid guid = await TaskAssistantModule.OpenTaskItemAsync(taskItem.TaskItemGuid);
var guid = await TaskAssistantFactory.Instance.OpenTaskItemAsync(taskItem.TaskItemGuid);
// TODO - retain the guid returned for use with CloseTaskItemAsync
}
catch (OpenTaskException e)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}
Close a Task Item
// find the first project task item which is open
var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault(t => t.IsOpen == true);
// if there isn't a project task item, return
if (taskItem == null)
return;
if (taskItem.IsOpen)
{
// close it
// NOTE : The task item will also be removed from the project
//At 2.x -
//TaskAssistantModule.CloseTaskAsync(taskItem.TaskItemGuid);
TaskAssistantFactory.Instance.CloseTaskItemAsync(taskItem.TaskItemGuid);
}
Export a Task Item
// get the first project task item
var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();
// if there isn't a project task item, return
if (taskItem == null)
return;
try
{
// export the task item to the c:\Temp folder
string exportFolder = @"c:\temp";
//At 2.x -
//string fileName = await TaskAssistantModule.ExportTaskAsync(taskItem.TaskItemGuid, exportFolder);
string fileName = await TaskAssistantFactory.Instance.ExportTaskItemAsync(taskItem.TaskItemGuid, exportFolder);
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Task saved to " + fileName);
}
catch (ExportTaskException e)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error saving task " + e.Message);
}
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.