How to get file paths for features and rasters using sdk open dialog button.

365
2
08-12-2020 07:38 AM
MatthewPebworth
New Contributor II

I am writing an add in that requires the input of several shapefiles and rasters. Unfortunately, the 'normal' open file dialog does not appropriately 'see' these file types. I need to be able to get file paths of these files without knowing the path before hand. Looking at the api reference this set of classes appear to be what i need. However, i am extremely new to programing in c# and am unsure how to achieve this. I have gotten as far as when button is clicked do a process##.

Tags (1)
0 Kudos
2 Replies
UmaHarano
Esri Regular Contributor

Hi Matthew,

You can use the BrowseProjectFilters and OpenItemDialog class to achieve what you need.

Pro offers a collection of existing BrowseProjectFilters that you can use. For example, "esri_browseDialogFilters_shapefiles" will allow you to browse just for shape files.  Note: You can also make your own filters for other file types. 

Here is a rough workflow:

  • Create a BrowseProjectFilter instance. You can instantiate it with one of the existing Pro filters (Shape file filter listed above is an example).
  • Create an OpenItemDialog object and set its "BrowseFilter" property to the BrowseProjectFilter instance created (above).
  • Call the Show method on the OpenItemDialog to display the dialog, filtering for the file types.

Here are some wiki pages that can help you:

Thanks

Uma

MatthewPebworth
New Contributor II

Thanks. The magic bullet for me was the need for the framework dispatcher property. This is what i was needing for future people in the same spot.

            var dlg = new OpenItemDialog();
            dlg.Title = "Select DEM Raster";

                FrameworkApplication.Current.Dispatcher.Invoke(() => {
                    var result = dlg.ShowDialog();
                    if (!dlg.ShowDialog().Value)
                        return;
                    var SelFile = dlg.Items.First();
                    ///Verify expected outcome
                    /// MessageBox.Show($@"Path: {SelFile.Path}");
                    FPath = SelFile.Path;
                    FileName = System.IO.Path.GetFileName(SelFile.Path);
                    txtDEM.Text = FileName;

                });

0 Kudos