

Public Class FolderConnectionProjectItem Inherits ArcGIS.Desktop.Internal.Catalog.ProjectItemInfoCrawl Implements ArcGIS.Desktop.Core.IMetadata, ArcGIS.Desktop.Core.IProjectItem, ArcGIS.Desktop.Core.ISearchableItem, System.ComponentModel.INotifyPropertyChanged
public class FolderConnectionProjectItem : ArcGIS.Desktop.Internal.Catalog.ProjectItemInfoCrawl, ArcGIS.Desktop.Core.IMetadata, ArcGIS.Desktop.Core.IProjectItem, ArcGIS.Desktop.Core.ISearchableItem, System.ComponentModel.INotifyPropertyChanged
A folder connection project item is a folder that has been added to the current project. The folder connection is a project item. The sub-folders and other items that can be accessed using the folder connection are items, not project items.
{
// Get all the folder connections in a project
IEnumerable<FolderConnectionProjectItem> projectFolders = Project.Current.GetItems<FolderConnectionProjectItem>();
// use projectFolders;
}
{
// 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"));
//Note: Needs QueuedTask to run
IEnumerable<Item> folderContents = folderConnection.GetItems();
}
{
// Remove a folder connection from a project; the folder stored on the local disk
// or the network is not deleted
//Note: Needs QueuedTask to run
{
bool result = false;
FolderConnectionProjectItem folderToRemove = Project.Current.GetItems<FolderConnectionProjectItem>()
.FirstOrDefault(folder => folder.Name.Equals("Data"));
if (folderToRemove != null)
result = Project.Current.RemoveItem(folderToRemove as IProjectItem);
// use result
}
}
{
//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.
}
}
{
FolderConnectionProjectItem folderProjItem = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myDataFolder"));
// Use folderProjItem;
}
{
// 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);
}
{
List<Item> _mxd = [];
//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());
}
}
}
{
var contentItem = Project.Current.GetItems<FolderConnectionProjectItem>().First();
//Check if the MCT is required for Refresh()
if (contentItem.IsMainThreadRequired)
{
// Note: Needs QueuedTask to 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);
}
}
{
//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);
}
System.Object
ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
ArcGIS.Desktop.Core.Item
ArcGIS.Desktop.Catalog.FolderConnectionProjectItem
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)