Select to view content in your preferred language

Using SaveItemDialog

09-19-2020 12:42 PM
Occasional Contributor

While there are several questions and answers and samples using OpenItemDialog, I haven't found any for SaveItemDialog which is giving me trouble.

I need to use this in an Add-In to ask the user for an output location for one or more featureclass(es) that may or may not already exist. If the selected output location is a featureclass then that gets created if necessary and then used, but if it is a workspace, then my code will determine the featureclass name and create it.

This works OK if a featureclass name is specified by the user except that the returned FilePath strips off .shp if a shapefile is specified and additional coding is required .

But, if a workspace is specified by the user, there are bigger problems: if a filegeodatabase is specified, then the returned Filepath has .GDB stripped off, and if a shapefile workspace (folder) then the "Save" button in the dialog is disabled, as if the dialog doesn't recognize a folder as a workspace, nor does it work using using the esri_browseDialogFilters_folders  filter.

A second point of confusion is the documentation for the AlwaysUseInitialLocation property. If set to true then the specified InitialLocation is used, but if False then "if not specified, the initial location may be the last location opened using the current filter"

May?  When or why doesn't it use the last location?

 Sub testSaveDialog()
    Dim pCompFilter As New BrowseProjectFilter

    Dim saveItemDlg As SaveItemDialog = New SaveItemDialog()
    saveItemDlg.BrowseFilter = pCompFilter
    saveItemDlg.Title = "Output location"
    saveItemDlg.InitialLocation = "F:\"
    saveItemDlg.OverwritePrompt = False
    saveItemDlg.AlwaysUseInitialLocation = True
    Dim ok As Boolean = saveItemDlg.ShowDialog()

    If ok = False Then
    End If
  End Sub

Tags (1)
0 Kudos
1 Reply
Occasional Contributor II

A bit disappointing that this question hasn't been addressed. There are a few things unclear about the SaveItemDialog() in the documentation - too much emphasis on the OpenItemDialog().

At the moment I am finding that I can't use a file filter of more than one type and have it honoured. The dialog just removes any suffix. So any help in regards to this would be useful (similar problem to the one initially outlined):


var dlg = new SaveItemDialog();
dlg.Title = "Save File";
dlg.OverwritePrompt = true;
// Create file filters for JSON and CSV
var jsonFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_browseFiles");
jsonFilter.FileExtension = "json";
jsonFilter.Name = "(*.json)";

var csvFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_browseFiles");
csvFilter.FileExtension = "csv";
csvFilter.Name = "(*.csv)";

BrowseProjectFilter compositeFilter = new BrowseProjectFilter();


dlg.BrowseFilter = compositeFilter;

bool? result = dlg.ShowDialog();

if (result == true)
    //!!!!! filePath has its file suffix missing!
    string filePath = dlg.FilePath;



0 Kudos