OpenTaskFileAsync(String,Guid) Method
Opens an ArcGIS Pro .esriTasks file. The file is added to the current project and loaded into the Tasks pane. Use the parameter to specify a particular task in the task file to be opened. Use the
GetTaskItemInfoAsync API call to obtain information about the tasks and their identifiers within the task file.
Parameters
- taskFile
- Full path to an .esriTasks file.
- taskGuid
- The unique identifier of a task in the task file to be opened. If the task can be found, it is opened and ready to be executed.
If the task cannot be found, the task file opens as if no task was specified.
Return Value
A Task returning the unique identifier of the task file opened. Use this unique identifier as parameters to other API calls such as
CloseTaskItemAsync or
ExportTaskItemAsync.
Open a specific Task in a Task File - .esriTasks file
// TODO - substitute your own .esriTasks file to be opened
string taskFile = @"c:\Tasks\Get Started.esriTasks";
await QueuedTask.Run(async () =>
{
try
{
// retrieve the task item information
//At 2.x -
//TaskItemInfo taskItemInfo = await TaskAssistantModule.GetTaskItemInfoAsync(taskFile);
var taskItemInfo = await TaskAssistantFactory.Instance.GetTaskItemInfoAsync(taskFile);
// find the first task
TaskInfo taskInfo = taskItemInfo.GetTasks().FirstOrDefault();
Guid guid = Guid.Empty;
if (taskInfo != null)
{
// if a task exists, open it
//At 2.x -
//guid = await TaskAssistantModule.OpenTaskAsync(taskFile, taskInfo.Guid);
guid = await TaskAssistantFactory.Instance.OpenTaskFileAsync(taskFile, taskInfo.Guid);
}
else
{
// else just open the task item
//At 2.x -
//guid = await TaskAssistantModule.OpenTaskAsync(taskFile);
guid = await TaskAssistantFactory.Instance.OpenTaskFileAsync(taskFile);
}
// TODO - retain the guid returned for use with CloseTaskItemAsync
}
catch (OpenTaskException e)
{
// exception thrown if task file doesn't exist or has incorrect format
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}
catch (TaskFileVersionException e)
{
// exception thrown if task file does not support returning task information
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}
});
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.