Select to view content in your preferred language

How to programmatically determine if editing session in progress for ArcGIS Pro?

08-15-2023 08:41 AM
New Contributor III

In ArcMap, I was able to determine if my users were in an edit session, or no. 

I know that an edit session isn't the same / not required in Pro. But many of my users are still new to Pro, so I suggest they follow the instructions in this link, to enable editing from the edit tab.

I have a c# Add-In for ArcGIS pro. I would like my program to be able to determine if my user is in an edit session, or no. 

I have tried things like this: 


       private async void CheckEditSession()
            // Check if an edit session is in progress
            bool editInProgress = false;

            await QueuedTask.Run(() =>
                editInProgress = EditingModule.Current.EditState == EditState.Editing;

            // Display appropriate message
            if (editInProgress)
                MessageBox.Show("Edit session in progress.");
                MessageBox.Show("Edit Session NOT in progress.");


But, as you can see, this syntax isn't really available. I'm having trouble finding any equivalent in the vast work of Pro Snippets. 

How can I programmatically determine whether or not my user is in an edit session, or not? 

2 Replies
MVP Esteemed Contributor

The Project class has the IsEditingEnabled property. This is the snippet to disable editing.

// if editing
if (Project.Current.IsEditingEnabled)
  var res = MessageBox.Show("Do you want to disable editing? Editing tools will be disabled",
                                                         "Disable Editing?", System.Windows.MessageBoxButton.YesNoCancel);
  if (res == System.Windows.MessageBoxResult.No ||
                res == System.Windows.MessageBoxResult.Cancel)

  //we must check for edits
  if (Project.Current.HasEdits)
    res = MessageBox.Show("Save edits?", "Save Edits?", System.Windows.MessageBoxButton.YesNoCancel);
    if (res == System.Windows.MessageBoxResult.Cancel)
    else if (res == System.Windows.MessageBoxResult.No)
New Contributor II

How would this work for a CoreHost application, where pro has been configured to require an edit session?




When configured this way, the Geodatabase.ApplyEdits method must be passed true, otherwise an exception is thrown. But in a CoreHost application, Project.Current is always null. How can I know when I must set the second parameter as true? Further, doing so get's rid of the exception and things appear to complete successfully, but the edit is not actually written to the attribute table.

0 Kudos