Using SaveItemDialog

306
0
09-19-2020 12:42 PM
BerndtNording
New Contributor III

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
    pCompFilter.AddFilter(BrowseProjectFilter.GetFilter("esri_browseDialogFilters_featureClasses_all"))
    pCompFilter.AddFilter(BrowseProjectFilter.GetFilter("esri_browseDialogFilters_workspaces_all"))
    pCompFilter.AddFilter(BrowseProjectFilter.GetFilter("esri_browseDialogFilters_folders"))

    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
      MsgBox("Aborted")
    Else
      MsgBox(saveItemDlg.FilePath)
    End If
  End Sub

Tags (1)
0 Kudos
0 Replies