ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Catalog Namespace / OpenItemDialog Class / ShowDialog Method
Example

In This Topic
    ShowDialog Method (OpenItemDialog)
    In This Topic
    Displays the Browse dialog box to open or use selcted items.
    Syntax
    public override Nullable<bool> ShowDialog()
    Public Overrides NotOverridable Function ShowDialog() As Nullable(Of Boolean)

    Return Value

    A boolean indicating if the Browse dialog was dismissed by pressing OK or Cancel.
    Remarks
    You can either configure the Browse dialog box properties first then display it with the ShowDialog method, or display the dialog box and then set its properties.
    Example
    Show_OpenItemDialog
    OpenItemDialog addToProjectDialog = new OpenItemDialog();
    addToProjectDialog.Title = "Add To Project";
    addToProjectDialog.InitialLocation = @"C:\Data\NewYork\Counties\Maps";
    addToProjectDialog.MultiSelect = true;
    addToProjectDialog.Filter = ItemFilters.Composite_Maps_Import;
    
    bool? ok = addToMapDialog.ShowDialog();
    
    if (ok == true)
    {
      IEnumerable<Item> selectedItems = addToMapDialog.Items;
      foreach (Item selectedItem in selectedItems)
        MapFactory.Instance.CreateMapFromItem(selectedItem);
    }
    
    Geodatabase Content from Browse Dialog
    var openDlg = new OpenItemDialog
    {
      Title = "Select a Feature Class",
      InitialLocation = @"C:\Data",
      MultiSelect = false,
      BrowseFilter = BrowseProjectFilter.GetFilter(ArcGIS.Desktop.Catalog.ItemFilters.GeodatabaseItems_All)
    };
    
    //show the browse dialog
    bool? ok = openDlg.ShowDialog();
    if (!ok.HasValue || openDlg.Items.Count() == 0)
      return;   //nothing selected
    
    await QueuedTask.Run(() =>
    {
      // get the item
      var item = openDlg.Items.First();
    
      // see if the item has a dataset
      if (ItemFactory.Instance.CanGetDataset(item))
      {
        // get it
        using (var ds = ItemFactory.Instance.GetDataset(item))
        {
          // access some properties
          var name = ds.GetName();
          var path = ds.GetPath();
    
          // if it's a featureclass
          if (ds is ArcGIS.Core.Data.FeatureClass fc)
          {
            // create a layer 
            var featureLayerParams = new FeatureLayerCreationParams(fc)
            {
              MapMemberIndex = 0
            };
            var layer = LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerParams, MapView.Active.Map);
    
            // continue
          }
        }
      }
    });
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also