Is there a way to validate the value that is in the name textbox on the SaveItemDialog when the Save button is clicked? Say for example the user typed a path into the textbox where the directory component did not exist on disc.
You are correct as SaveItemDialog doesn't validate the path at all. I guess the designers of SaveItemDialog allowed for invalid paths to be entered assuming the caller would verify the validity. I tried this in ArcGIS Pro trying to save a layer by entering a path that doesn't exist:
After i clicked save i get this message in Pro:
i guess it's conceivable that the calling business logic could attempt to create the path if it doesn't exist.
However, in ArcGIS Pro after the error is displayed, the caller immediately pops up the SaveItemDialog again with the 'bad path entry' using the bad path as the initial location:
code example
var dlg = new SaveItemDialog();dlg.Title = "title";dlg.OverwritePrompt = true;dlg.DefaultExt = "gmcx";dlg.InitialLocation = @C:\Temp;
var fileFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_browseFiles");fileFilter.FileExtension = "gmcx";//restrict to specific extensions as neededfileFilter.BrowsingFilesMode = false;
//Specify a name to show in the filter dropdown combo box - otherwise the name//will show as "Default"fileFilter.Name = "(*.gmcx)";dlg.BrowseFilter = fileFilter;
bool? saveFile = dlg.ShowDialog();
if (saveFile == true){NewCatalogPath = dlg.FilePath;}
I have a custom Item with a .gmcx extension, and I have created a BrowseProjectFilter to limitthe browsing to files with .gmcx extensions.
The issue I would like to fix if possible is that the user can type into the Name textbox, enter apath using a directory that doesn't exist and yet the Save button is available and FilePath returnedis using a non-existant directory.
See the attached image as an example. The user can enter c:\directoryThatDoesNotExist\newgmcx andclicking the Save button returns a dlg.FilePath of c:\directoryThatDoesNotExist\newgmcx.gmcx
Is there a way to have the dialog validate that everything left of newgmcx actually exists beforesaveFile == true?
When this was tried using microsoft's SaveFileDialog, a warning is given and the workflow stopped.See second attachment.
Thanks for your help
The validation is working for me. You can specify the BrowseFilter / Filter properties to further restrict the input options. SaveItemDialog Class—ArcGIS Pro
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.