Select to view content in your preferred language

How to make InitialLocation of OpenItemDialog to work?

1022
4
Jump to solution
03-25-2020 11:53 PM
GKmieliauskas
Esri Regular Contributor

Hi,

I have tried to use InitialLocation of OpenItemDialog but unsuccessfully. To check not from my code I use FolderConnectionManager sample. InitialLocation folder exists, but it is not in the project folder connections. Maybe that is the reason?

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi,

Use the AlwaysUseInitialLocation property to force the OpenItemDialog to open the folder specified in the InitialLocation property. The behavior of the dialog is to open the last location opened using the current filter if you do not set this property to true.

Thanks

Uma

View solution in original post

0 Kudos
4 Replies
by Anonymous User
Not applicable

Hi Gintautas Kmieliauskas,

You are right initial location folder path need to be in the project folder connection.

So you have two options to try

Add the folder connection first before you use OpenItemDialog that with this code.

 

 await QueuedTask.Run(() =>
                        {
                            var folderToAdd = ItemFactory.Instance.Create([initial path]) as IProjectItem;
                            Project.Current.AddItem(folderToAdd);                            
                        });

or 

Use the FolderBrowserDialog 

Trade off is that UI does not look like ArcGIS pro theme.

And also quicker, if you just want your user to select a folder path.

Below is the sample code.

using (FolderBrowserDialog tmpDestination = new FolderBrowserDialog())
                {
                    tmpDestination.Description = "Open your desired folder destination";
                    tmpDestination.SelectedPath = [your init folder path];
                    if (tmpDestination.ShowDialog() == DialogResult.OK)
                    {
                        string userSelectedFolderPath = tmpDestination.SelectedPath;
                    }
                }

You shall need to replace the sample place holder [] with your variable accordingly.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Than,

Thanks for help, but it doesn't work for me. I have tried your code with AddItem and saved in project folder connection but it doesn't work in both cases.

In my case I need to select rasters, lyrx'es and etc.

I have ArcGIS Pro 2.5 installed.

UmaHarano
Esri Regular Contributor

Hi,

Use the AlwaysUseInitialLocation property to force the OpenItemDialog to open the folder specified in the InitialLocation property. The behavior of the dialog is to open the last location opened using the current filter if you do not set this property to true.

Thanks

Uma

0 Kudos
GKmieliauskas
Esri Regular Contributor

Thanks Uma.

It works know.

It would be nice in API reference to see near InitialLocation description note about AlwaysUseInitialLocation property behavior.

0 Kudos