FolderConnectionProjectItem Class
Get FolderConnectionProjectItems
/// Get all the folder connections in a project
IEnumerable<FolderConnectionProjectItem> projectFolders = Project.Current.GetItems<FolderConnectionProjectItem>();
Get Project Items by ProjectItem type
/// Get all the items that can be accessed from a folder connection. The items immediately
/// contained by a folder, that is, the folder's children, are returned including folders
/// and individual items that can be used in ArcGIS Pro. This method does not return all
/// items contained by any sub-folder that can be accessed from the folder connection.
FolderConnectionProjectItem folderConnection = Project.Current.GetItems<FolderConnectionProjectItem>()
.FirstOrDefault((folder => folder.Name.Equals("Data")));
await QueuedTask.Run(() =>
{
IEnumerable<Item> folderContents = folderConnection.GetItems();
});
Remove FolderConnection From Project
/// Remove a folder connection from a project; the folder stored on the local disk
/// or the network is not deleted
FolderConnectionProjectItem folderToRemove = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(folder => folder.Name.Equals("PlantSpecies"));
if (folderToRemove != null)
Project.Current.RemoveItem(folderToRemove as IProjectItem);
Get all folder connections in a project
//Gets all the folder connections in the current project
var projectFolders = Project.Current.GetItems<FolderConnectionProjectItem>();
foreach (var FolderItem in projectFolders)
{
//Do Something with the Folder connection.
}
Get a specific folder connection
//Gets a specific folder connection in the current project
FolderConnectionProjectItem myProjectFolder = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(folderPI => folderPI.Name.Equals("myDataFolder"));
Remove a specific folder connection
// Remove a folder connection from a project; the folder stored on the local disk or the network is not deleted
FolderConnectionProjectItem folderToRemove = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(myfolder => myfolder.Name.Equals("PlantSpecies"));
if (folderToRemove != null)
Project.Current.RemoveItem(folderToRemove as IProjectItem);
Search project for a specific item
List<Item> _mxd = new List<Item>();
//Gets all the folder connections in the current project
var allFoldersItem = Project.Current.GetItems<FolderConnectionProjectItem>();
if (allFoldersItem != null)
{
//iterate through all the FolderConnectionProjectItems found
foreach (var folderItem in allFoldersItem)
{
//Search for mxd files in that folder connection and add it to the List<T>
//Note:ArcGIS Pro automatically creates and dynamically updates a searchable index as you build and work with projects.
//Items are indexed when they are added to a project.
//The first time a folder or database is indexed, indexing may take a while if it contains a large number of items.
//While the index is being created, searches will not return any results.
_mxd.AddRange(folderItem.GetItems());
}
}
Refresh the child item for a folder connection Item
var contentItem = Project.Current.GetItems<FolderConnectionProjectItem>().First();
//var contentItem = ...
//Check if the MCT is required for Refresh()
if (contentItem.IsMainThreadRequired)
{
//QueuedTask.Run must be used if item.IsMainThreadRequired
//returns true
QueuedTask.Run(() => contentItem.Refresh());
}
else
{
//if item.IsMainThreadRequired returns false, any
//thread can be used to invoke Refresh(), though
//BackgroundTask is preferred.
contentItem.Refresh();
//Or, via BackgroundTask
ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(() =>
contentItem.Refresh(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);
}
ProjectItem: Get an Item or Find an Item
//GetItems searches project content
var map = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name == "Map1");
var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(m => m.Name == "Layout1");
var folders = Project.Current.GetItems<FolderConnectionProjectItem>();
var style = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 3D");
//Find item uses a catalog path. The path can be to a file or dataset
var fcPath = @"C:\Pro\CommunitySampleData\Interacting with Maps\Interacting with Maps.gdb\Crimes";
var pdfPath = @"C:\Temp\Layout1.pdf";
var imgPath = @"C:\Temp\AddinDesktop16.png";
var fc = Project.Current.FindItem(fcPath);
var pdf = Project.Current.FindItem(pdfPath);
var img = Project.Current.FindItem(imgPath);
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3.0 or higher.