Skip to content

ProGuide Custom Browse Dialog Filters

UmaHarano edited this page Nov 6, 2023 · 9 revisions

Code snippets listed in this guide are also used by the following sample code: OpenItemDialogBrowseFilter sample code

Language:              C#  
Subject:               Content  
Contributor:           ArcGIS Pro SDK Team <arcgisprosdk@esri.com>  
Organization:          Esri, http://www.esri.com  
Date:                  12/21/2022  
ArcGIS Pro:            3.2  
Visual Studio:         2022 

This guide demonstrates how to create a custom browse dialog filter which is used with an OpenItemDialog and SaveItemDialog. These filters allow browsing to specific file types. See the ProConcepts: Project Items, Browse Dialog Filters topic for more information.

This topic demonstrates how to make the following browse dialog filters:

Prerequisites

  • Download and install the sample data required for this guide as instructed in ArcGIS Pro SDK Community Samples Releases.
  • Create a new ArcGIS Pro Module Add-in, and name the project CustomBrowseDialogFilters. If you are not familiar with the ArcGIS Pro SDK, you can follow the steps in the ProGuide Build your first add-in to get started.

Browse filter to view polygon feature classes in a file geodatabase

This filter will allow you to browse for polygon feature classes in a file geodatabase.

Polygon FGDB

  1. Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenPolygonFeatureClasses.cs.
  2. Add the following snippet into the OnClick method of the OpenPolygonFeatureClasses.cs.
 //Create an instance of BrowseProjectFilter class
 BrowseProjectFilter bf = new BrowseProjectFilter {
    //Name the filter
    Name = "Polygon feature class in FGDB"
 };

    //Add typeID for Polygon feature class
    bf.AddCanBeTypeId("fgdb_fc_polygon");
    //Allow only File GDBs
    bf.AddDontBrowseIntoFlag(BrowseProjectFilter.FilterFlag.DontBrowseFiles);
    bf.AddDoBrowseIntoTypeId("database_fgdb");
    //Display only folders and GDB in the browse dialog
    bf.Includes.Add("FolderConnection");
    bf.Includes.Add("GDB");
    //Does not display Online places in the browse dialog
    bf.Excludes.Add("esri_browsePlaces_Online");
    
    //Display the filter in an Open Item dialog
    OpenItemDialog aNewFilter = new OpenItemDialog
    {
        Title = "Open Polygon Feature classes",
        InitialLocation = @"C:\Data",
        MultiSelect = false,
        BrowseFilter = bf               
    };
    bool? ok = aNewFilter.ShowDialog();
  1. Build the solution and click start to launch Pro.
  2. Open any project.
  3. Click the Add-in tab and click the OpenPolygonFeatureClasses button.
  4. The OpentItemDialog will be displayed. Browse to a file geodatabase that has polygon feature classes to view them.

Create browse filter in DAML to view line feature classes in a file geodatabase

This filter will display line feature classes in a file geodatabase. The filter is configured in DAML. The BrowseProjectFilter instance is created by passing in the DAML id to the constructor.

Line FGDB

  1. In the add-in's config.daml file, add the following code snippet after the "<modules>" tag. This snippet configures a filter with id "NewLineFeatures_Filter" that displays line feature classes in a file geodatabase.
  ....
  <modules></modules>
    <categories>
      <updateCategory refID="esri_browseFilters">
        <insertComponent id="NewLineFeatures_Filter">
          <content displayName="Line feature class in FGDB" 
                   include="FolderConnection, GDB" 
                   exclude="esri_browsePlaces_Online">
              <canBeTypeIds>
                 <type id="fgdb_fc_line" />
              </canBeTypeIds>
              <dontBrowseIntoFlags>
                 <type id="DontBrowseFiles" />
              </dontBrowseIntoFlags>
              <doBrowseIntoTypeIds>
                 <type id="database_fgdb" />
              </doBrowseIntoTypeIds>
            </content>
         </insertComponent>
       </updateCategory>
     </categories>
  1. Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenLineFeatureClasses.cs.
  2. Add the following snippet into the OnClick method of the OpenLineFeatureClasses.cs.
    //Use our filter DAML id - i.e. <insertComponent id="NewLineFeatures_Filter">
    var bf = new BrowseProjectFilter("NewLineFeatures_Filter");
    //Display the filter in an Open Item dialog
    OpenItemDialog op = new OpenItemDialog
    {
        Title = "Open Line Feature classes",
        InitialLocation = @"C:\Data",
        MultiSelect = false,
        BrowseFilter = bf
    };
    bool? ok = op.ShowDialog();
  1. Build the solution and click start to launch Pro.
  2. Open any project.
  3. Click the Add-in tab and click the OpenLineFeatureClasses button.
  4. The OpentItemDialog will be displayed.
  5. Browse to a folder that has a file geodatabase with line feature classes to view them.

Use Pro's Geodatabase filter

This browse filter uses an existing Pro "esri_browseDialogFilters_geodatabases" filter. Geodatabase

  1. Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenGeodatabases.cs.
  2. Add the following snippet into the OnClick method of the OpenGeodatabases.cs.
    //Create instance of BrowseProjectFilter using the id for Pro's file geodatabase filter
  BrowseProjectFilter bf = new BrowseProjectFilter("esri_browseDialogFilters_geodatabases");
    //Display the filter in an Open Item dialog
    OpenItemDialog aNewFilter = new OpenItemDialog
    {
        Title = "Open Geodatabases",
        InitialLocation = @"C:\Data",
        MultiSelect = false,
        //Set the BrowseFilter property to Pro's Geodatabase filter.
        BrowseFilter = bf
    };
    bool? ok = aNewFilter.ShowDialog();
  1. Build the solution and click start to launch Pro.
  2. Open any project.
  3. Click the Add-in tab and click the OpenGeodatabases button.
  4. The OpentItemDialog will be displayed.
  5. Browse to a folder that has geodatabases to view them.

Modify Pro's LYRX file filter to include LYR files

This browse filter modifies Pro's "esri_browseDialogFilters_layers_lyrx" browse filter to display lyr files also.

Lyr and Lyrx

  1. Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenLayerAndLayerXFiles.cs.
  2. Add the following snippet into the OnClick method of the OpenLayerAndLayerXFiles.cs.
    //Create BrowseProjectFilter class instance
    //Pass in id of Pro's Lyrx filter
    BrowseProjectFilter lyrXLyrGeneral = new BrowseProjectFilter(
      "esri_browseDialogFilters_layers_lyrx");
    lyrXLyrGeneral.Name = "Layer Files (LYRX) and Layer Files (LYR)";

    //Additionally, add the type id for lyr files to this BrowseProjectFilter class
    lyrXLyrGeneral.AddCanBeTypeId("layer_general");
    lyrXLyrGeneral.AddDontBrowseIntoFlag(BrowseProjectFilter.FilterFlag.DontBrowseFiles);
    //Display only folders and GDB in the browse dialog
    lyrXLyrGeneral.Includes.Add("FolderConnection");
    lyrXLyrGeneral.Includes.Add("GDB");

    //Do not display Online places in the browse dialog
    lyrXLyrGeneral.Excludes.Add("esri_browsePlaces_Online");

    //Display the filter in an Open Item dialog
    OpenItemDialog aNewFilter = new OpenItemDialog
    {
        Title = "Open LyrX and Lyr General files",
        InitialLocation = @"C:\Data",
        MultiSelect = false,
        BrowseFilter = lyrXLyrGeneral
    };
    bool? ok = aNewFilter.ShowDialog();
  1. Build the solution and click start to launch Pro.
  2. Open any project.
  3. Click the Add-in tab and click the OpenLayerAndLayerXFiles button.
  4. The OpentItemDialog will be displayed.
  5. Browse to a folder that has any ".lyr" and ".lyrx" files to view them.

Composite filter

In an OpenItemDialog, you can add multiple filters to the filter dropdown list. This creates a browse experience that allows you to pick the type of file you want to browse for in that dialog. This composite filter example will allow you to view "lyr" or "lyrx" files.

Composite Filter

  1. Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenLayerOrLayerXFiles.cs.
  2. Add the following snippet into the OnClick method of the OpenLayerOrLayerXFiles.cs.
    BrowseProjectFilter compositeFilter = new BrowseProjectFilter();

    //Add an existing Pro Lyr filter to the BrowseProjectFilter instance
    compositeFilter.AddFilter(BrowseProjectFilter.GetFilter(
                                 "esri_browseDialogFilters_layers_lyr"));
    //Add an existing Pro Lyrx filter to the BrowseProjectFilter instance
    compositeFilter.AddFilter(BrowseProjectFilter.GetFilter(
                                 "esri_browseDialogFilters_layers_lyrx"));

    //Customize the "Browse Places"
    compositeFilter.Includes.Add("FolderConnection");
    compositeFilter.Excludes.Add("esri_browsePlaces_Online");

    //Display the filter in an Open Item dialog
    OpenItemDialog op = new OpenItemDialog
    {
        Title = "Open LYR or LYRX files",
        InitialLocation = @"C:\Data",
        MultiSelect = false,
        BrowseFilter = compositeFilter
    };
    bool? ok = op.ShowDialog();
  1. Build the solution and click start to launch Pro.
  2. Open any project.
  3. Click the Add-in tab and click the OpenLayerOrLayerXFiles button.
  4. The OpenItemDialog will be displayed. Notice the file filter drop down at the bottom right. You will notice two choices to filter files with - Layer Files (LYRX) and Layer Files (LYR).
  5. Browse to a folder that has any ".lyr" and ".lyrx" files to view them.

Browse filter to view a custom item

This filter will allow you to view a custom item.
Note: Custom items are a special type of item that allows 3rd parties to add (or "include") their proprietary file types into Pro and to define the custom behavior, context menu items, etc. for "that" particular content type. In this example, "customItem" is a type that registered with Pro. ProConcepts: Custom Items

Custom Item

  1. Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenCustomItem.cs.
  2. Add the following snippet into the OnClick method of the OpenCustomItem.cs.
    BrowseProjectFilter bf = new BrowseProjectFilter();
    //Name the filter
    bf.Name = "\"customItem\" files";
    //Add typeID for Filters_ProGPXItem custom item.
    //Custom items 
    bf.AddCanBeTypeId("Filters_ProGPXItem");
    //Does not allow browising into files
    bf.AddDontBrowseIntoFlag(BrowseProjectFilter.FilterFlag.DontBrowseFiles);
    //Display only folders and GDB in the browse dialog
    bf.Includes.Add("FolderConnection");
    //Does not display Online places in the browse dialog
    bf.Excludes.Add("esri_browsePlaces_Online");
    		    
    //Display the filter in an Open Item dialog
    OpenItemDialog aNewFilter = new OpenItemDialog
    {
        Title = "Open \"customItem\"",
        InitialLocation = @"C:\Data",
        MultiSelect = false,
        BrowseFilter = bf
    };
    bool? ok = aNewFilter.ShowDialog();
  3. Build the solution and click start to launch Pro.
  4. Open any project.
  5. Click the Add-in tab and click the OpenCustomItem button.
  6. The OpentItemDialog will be displayed. If you have the community samples installed, browse to C:\Data\BrowseDialogFiltersBrowse to view a file with the "customItem" file extension.

Display custom item in "add to map" dialog

This demonstrates how to view a custom item in Pro's "Add To Map" dialog.

  1. Add an "ArcGIS Pro Custom Item" to the add-in project using the ArcGIS Pro SDK templates. Name the class file ProGPXItem.cs.
  2. The template adds the following snippet that registers the CustomBrowseDialogFilters_ProGPXItem item with the esri_customItems category. Locate this code snippet in your add-in's config.daml. Note: In this example below, the add-in project name is "CustomBrowseDialogFilters". The Custom item component id stubbed out by Visual Studio is "CustomBrowseDialogFilters_ProGPXItem".
    <categories>
        <updateCategory refID="esri_customItems">
          <insertComponent id="CustomBrowseDialogFilters_ProGPXItem" 
                  className="CustomBrowseDialogFilters_ProGPXItem">
            <content displayName="CustomBrowseDialogFilters_ProGPXItem" 
                fileExtension="acmeXXXX" isContainer="false" 
                keywords="CustomBrowseDialogFilters_ProGPXItem"
                contextMenuID="CustomBrowseDialogFilters_ProGPXItem_ContextMenu">
              <filterFlags>
                <!--Change this flag as needed. See FilterFlag enum. Example: 
                    AddToMap, DontBrowseFiles...-->
                <type id="File" />
              </filterFlags>
            </content>
          </insertComponent>
        </updateCategory>
    </categories>
  3. Modify the "fileExtension" attribute of the content element to be "customItem".
  4. Modify the id attribute of the content > filterFlags > type element to be "AddToMap". It is set to "File" by default. The completed code snippet is given below:
    <categories>
        <updateCategory refID="esri_customItems">
          <insertComponent id="CustomBrowseDialogFilters_ProGPXItem" 
                className="CustomBrowseDialogFilters_ProGPXItem">
            <content displayName="CustomBrowseDialogFilters_ProGPXItem" 
                  fileExtension="customItem" isContainer="false" 
                  keywords="CustomBrowseDialogFilters_ProGPXItem" 
                  contextMenuID="CustomBrowseDialogFilters_ProGPXItem_ContextMenu">
              <filterFlags>
                <!--Change this flag as needed. See FilterFlag enum. Example: 
                    AddToMap, DontBrowseFiles...-->
                <type id="AddToMap" />
              </filterFlags>
            </content>
          </insertComponent>
        </updateCategory>
    </categories>
  5. Build the solution and click start to launch Pro.
  6. Open any project with a MapView.
  7. With the MapView active, click the Add to map button on the Pro ribbon.
  8. If you have the community samples installed, browse to C:\Data\BrowseDialogFiltersBrowse to view a file with the "customItem" file extension.

Developing with ArcGIS Pro

    Migration


Framework

    Add-ins

    Configurations

    Customization

    Styling


Arcade


Content


CoreHost


DataReviewer


Editing


Geodatabase

    3D Analyst Data

    Plugin Datasources

    Topology

    Object Model Diagram


Geometry

    Relational Operations


Geoprocessing


Knowledge Graph


Layouts

    Reports


Map Authoring

    3D Analyst

    CIM

    Graphics

    Scene

    Stream

    Voxel


Map Exploration

    Map Tools


Networks

    Network Diagrams


Parcel Fabric


Raster


Sharing


Tasks


Workflow Manager Classic


Workflow Manager


Reference

Clone this wiki locally