ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.TaskAssistant Namespace / TaskAssistantFactory Class / OpenTaskFileAsync Method / OpenTaskFileAsync(String) Method
Full path to an .esriTasks file.
Example

In This Topic
    OpenTaskFileAsync(String) Method
    In This Topic
    Opens an ArcGIS Pro .esriTasks file. The file is added to the current project and loaded into the Tasks pane.
    Syntax
    public Task<Guid> OpenTaskFileAsync( 
       string taskFile
    )
    Public Overloads Function OpenTaskFileAsync( _
       ByVal taskFile As String _
    ) As Task(Of Guid)

    Parameters

    taskFile
    Full path to an .esriTasks file.

    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.
    Exceptions
    ExceptionDescription
    Error opening the task file. For example the taskFile is invalid or the Tasks pane is in Designer mode and editing another task item.
    This must be called on the UI thread.
    Remarks
    If the Tasks pane is not already visible, it will be opened. If the Tasks pane is visible, any current task item will be unloaded to allow the new item to be loaded.

    If the Tasks pane is in Designer mode; then an ArcGIS.Desktop.TaskAssistant.Exceptions.OpenTaskException will be thrown. Task files can only be opened if the Tasks pane is not in Designer mode.

    Example
    Open a Task File - .esriTasks file
    // Open a task file
    try
    {
      // TODO - substitute your own .esriTasks file to be opened
      string taskFile = @"c:\Tasks\Get Started.esriTasks";
      //At 2.x -
      //System.Guid guid = await TaskAssistantModule.OpenTaskAsync(taskFile);
      var 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);
    }
    
    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);
      }
    
    });
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also