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?
Solved! Go to Solution.
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
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.
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.
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
Thanks Uma.
It works know.
It would be nice in API reference to see near InitialLocation description note about AlwaysUseInitialLocation property behavior.