ProGuide Custom Browse Dialog Filters - Esri/arcgis-pro-sdk GitHub Wiki
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 <[email protected]>
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:
- Browse filter to view polygon feature classes in a file geodatabase
- Create browse filter in DAML to view line feature classes in a file geodatabase
- Use Pro's Geodatabase filter
- Modify Pro's LYRX file filter to include LYR files
- Composite filter
- Browse filter to view a custom item
- Display custom item in "add to map" dialog
- 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.
This filter will allow you to browse for polygon feature classes in a file geodatabase.
- Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenPolygonFeatureClasses.cs.
- 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();
- Build the solution and click start to launch Pro.
- Open any project.
- Click the Add-in tab and click the OpenPolygonFeatureClasses button.
- The OpentItemDialog will be displayed. Browse to a file geodatabase that has polygon feature classes to view them.
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.
- 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>
- Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenLineFeatureClasses.cs.
- 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();
- Build the solution and click start to launch Pro.
- Open any project.
- Click the Add-in tab and click the OpenLineFeatureClasses button.
- The OpentItemDialog will be displayed.
- Browse to a folder that has a file geodatabase with line feature classes to view them.
This browse filter uses an existing Pro "esri_browseDialogFilters_geodatabases" filter.
- Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenGeodatabases.cs.
- 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();
- Build the solution and click start to launch Pro.
- Open any project.
- Click the Add-in tab and click the OpenGeodatabases button.
- The OpentItemDialog will be displayed.
- Browse to a folder that has geodatabases to view them.
This browse filter modifies Pro's "esri_browseDialogFilters_layers_lyrx" browse filter to display lyr files also.
- Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenLayerAndLayerXFiles.cs.
- 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();
- Build the solution and click start to launch Pro.
- Open any project.
- Click the Add-in tab and click the OpenLayerAndLayerXFiles button.
- The OpentItemDialog will be displayed.
- Browse to a folder that has any ".lyr" and ".lyrx" files to view them.
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.
- Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenLayerOrLayerXFiles.cs.
- 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();
- Build the solution and click start to launch Pro.
- Open any project.
- Click the Add-in tab and click the OpenLayerOrLayerXFiles button.
- 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).
- Browse to a folder that has any ".lyr" and ".lyrx" files to view them.
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
- Add a new ArcGIS Pro button item to the add-in project. Name the button class file OpenCustomItem.cs.
- 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();
- Build the solution and click start to launch Pro.
- Open any project.
- Click the Add-in tab and click the OpenCustomItem button.
- 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.
This demonstrates how to view a custom item in Pro's "Add To Map" dialog.
- Add an "ArcGIS Pro Custom Item" to the add-in project using the ArcGIS Pro SDK templates. Name the class file ProGPXItem.cs.
- The template adds the following snippet that registers the
CustomBrowseDialogFilters_ProGPXItem
item with theesri_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>
- Modify the "fileExtension" attribute of the content element to be "customItem".
- 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>
- Build the solution and click start to launch Pro.
- Open any project with a MapView.
- With the MapView active, click the Add to map button on the Pro ribbon.
- If you have the community samples installed, browse to C:\Data\BrowseDialogFiltersBrowse to view a file with the "customItem" file extension.