Validation within SaveItemDialog

1241
4
Jump to solution
04-13-2023 07:10 AM
StevenCorpus
Emerging Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

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:

Wolf_0-1681916931026.png

After i clicked save i get this message in Pro:

Wolf_1-1681917058292.png

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:

Wolf_4-1681917505902.png

 

 

 

View solution in original post

0 Kudos
4 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

The validation is working for me.  You can specify the BrowseFilter / Filter properties to further restrict the input options.  SaveItemDialog Class—ArcGIS Pro

0 Kudos
StevenCorpus
Emerging Contributor

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 needed
fileFilter.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 limit
the 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 a
path using a directory that doesn't exist and yet the Save button is available and FilePath returned
is using a non-existant directory.

See the attached image as an example. The user can enter c:\directoryThatDoesNotExist\newgmcx and
clicking 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 before
saveFile == true?

When this was tried using microsoft's SaveFileDialog, a warning is given and the workflow stopped.
See second attachment.

 

Thanks for your help

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

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:

Wolf_0-1681916931026.png

After i clicked save i get this message in Pro:

Wolf_1-1681917058292.png

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:

Wolf_4-1681917505902.png

 

 

 

0 Kudos
StevenCorpus
Emerging Contributor
Thanks for verifying this for me. I have made workarounds in my code. I just wanted to be sure that this was necessary.
0 Kudos