Select shapefiles using OpenItemDialog in Pro SDK

1204
5
11-03-2020 12:07 PM
AlexZlotin1
New Contributor III

I am trying to configure BrowseProjectFilter of OpenItemDialog so only line shapefiles can be selected. Here is the code I am using:

BrowseProjectFilter browseFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_shapefiles");

OpenItemDialog browseDialog = new OpenItemDialog

{
   Title = "Select line shapefile",
   MultiSelect = false,
   BrowseFilter = browseFilter
};
browseDialog.ShowDialog();

This returns shapefiles of all geometry types. Is there a way to configure the filter to display shapefiles with line geometry type only? I have tried applying the AddCanBeTypeId below but it does not make any difference. 

browseFilter.AddCanBeTypeId("shapefile_line");

I am using Pro 2.6 SDK. Thanks!

0 Kudos
5 Replies
UmaHarano
Esri Regular Contributor

Hi,

I added the "shapefile_general" typeID to get this to work.

BrowseProjectFilter browseFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_shapefiles");
browseFilter.AddCanBeTypeId("shapefile_general");
browseFilter.AddCanBeTypeId("shapefile_line");
OpenItemDialog browseDialog = new OpenItemDialog
{....

Thanks

Uma

0 Kudos
AlexZlotin1
New Contributor III

Thanks Uma! This is not working for me though. The filter alone without AddCanBeTypeId's shows shapefiles of all geometry types:

BrowseProjectFilter browseFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_shapefiles");
OpenItemDialog browseDialog = new OpenItemDialog {….}

With the AddCanBeTypeId lines added, I still see shapefiles of all geometry types. I also see file geodatabases located in the same folder, and can navigate to the feature classes in the file geodatabases:

BrowseProjectFilter browseFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_shapefiles");

browseFilter.AddCanBeTypeId("shapefile_general");
browseFilter.AddCanBeTypeId("shapefile_line");

OpenItemDialog browseDialog = new OpenItemDialog {….}

 

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Alex,

Can you try using the AddMustNotBeTypeId method to pass in the typeIDs to not display?

BrowseProjectFilter browseFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_shapefiles");
browseFilter.AddCanBeTypeId("shapefile_general");
browseFilter.AddCanBeTypeId("shapefile_line");
browseFilter.AddMustNotBeTypeId("shapefile_point");
//Add other typeIDs of shape files to not show.

Also, this is how my dialog looks (below). I have a file GDB in this location. I don't see it nor am I able to browse into it.  So not sure what is happening there.

0 Kudos
AlexZlotin1
New Contributor III

Thanks! I can provide more information now after additional testing. The code to open the OpenItemDialog is executed from a Pro button. When I launch Pro and click the button for the first time, the OpenItemDialog loads, but it shows all types of shapefiles (file geodatabases are excluded). After I cancel from the dialog and click the button again, the OpenItemDialog now correctly shows only line shapefiles. From this point on the filter works correctly. Any ideas why this is happening?

Here is the BrowseProjectFilter configuration:

BrowseProjectFilter browseFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_shapefiles");

browseFilter.AddCanBeTypeId("shapefile_general");

browseFilter.AddMustNotBeTypeId("shapefile_polygon");

browseFilter.AddMustNotBeTypeId("shapefile_point");

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Alex,

Can you make a small sample add-in project with just this button and send it to me?

An attachment posted here will work. I can take a look and see if I can help.

Thanks

Uma

0 Kudos