How do I add filename, filter in saveitemdialog

507
2
06-04-2020 09:21 PM
by Anonymous User
Not applicable

Hi Guys,

I am using this code.

SaveItemDialog tmpDestination = new SaveItemDialog()
            {
                Title = "ASCII Output file name",
                DefaultExt = "txt",
                Filter = "*.txt"
            };
            
            if (tmpDestination.ShowDialog() == true)
            {

Normally with savefileDialog, I can use FileName property to add default file name for user, Is there any way in saveitemdialog?

And When I add Filter property, it display like "Default" in file extension below,  how to make it obvious like txt extension?

0 Kudos
2 Replies
UmaHarano
Esri Regular Contributor

There is a built in browse dialog filter for text files you could use.  Like this:

      var txtFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_textFiles_txt");
     
      SaveItemDialog saveTxtFileDialog = new SaveItemDialog()
      {
        Title = "Save Txt File",
        InitialLocation = @"C:\Data\",
        BrowseFilter = txtFilter,
        OverwritePrompt = true
      };
      bool? result = saveTxtFileDialog.ShowDialog();

Or you could make your own filter to use like this:

var txtFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_browseFiles");
      txtFilter.FileExtension = "*.txt;";
      txtFilter.BrowsingFilesMode = true;
      
      txtFilter.Name = "Txt files (*.txt;)";
      SaveItemDialog saveTxtFileDialog = new SaveItemDialog()
      {
        Title = "Save Txt File",
        InitialLocation = @"C:\Data\",
        BrowseFilter = txtFilter,
        OverwritePrompt = true
      };
      bool? result = saveTxtFileDialog.ShowDialog();
by Anonymous User
Not applicable

Thank Uma Harano‌,

It help for filter dropdown default, but How shall I add default file name in name textbox?

 string initialLocation = ZetaLongPaths.ZlpPathHelper.Combine(Project.Current.URI, this.SelectedLayer.Name + "_Ascii.txt");
            var txtFilter = BrowseProjectFilter.GetFilter("esri_browseDialogFilters_browseFiles");
            txtFilter.FileExtension = "*.txt";//restrict to specific extensions as needed
            txtFilter.BrowsingFilesMode = true;
            //Specify a name to show in the filter dropdown combo box - otherwise the name will show as "Default"
            txtFilter.Name = "Text Files (*.txt)";

            SaveItemDialog tmpDestination = new SaveItemDialog()
            {
                Title = "ASCII Output file name",
                AlwaysUseInitialLocation = true,         
                InitialLocation = initialLocation,
                BrowseFilter = txtFilter,
                OverwritePrompt = true
            };

0 Kudos