Create Method (ItemFactory)
Creates a
Item representing the resource identified by the Uri
Parameters
- uri
-
The full path to the item on disk or portal item identifier for a resource that will be created
- itemType
- (optional) The type of item that is expected to be created, as specified by ItemFactory.ItemType. (default value = PathItem)
Return Value
Item or null if an item cannot be created or found
Importing Maps To Project
/// Import a mxd
Item mxdToImport = ItemFactory.Instance.Create(@"C:\Projects\RegionalSurvey\LatestResults.mxd");
var addedMxd = await QueuedTask.Run(
() => Project.Current.AddItem(mxdToImport as IProjectItem));
/// Add map package
Item mapPackageToAdd = ItemFactory.Instance.Create(@"c:\Data\Map.mpkx");
var addedMapPackage = await QueuedTask.Run(
() => Project.Current.AddItem(mapPackageToAdd as IProjectItem));
/// Add an exported Pro map
Item proMapToAdd = ItemFactory.Instance.Create(@"C:\ExportedMaps\Election\Districts.mapx");
var addedMapProjectItem = await QueuedTask.Run(
() => Project.Current.AddItem(proMapToAdd as IProjectItem));
Importing Maps To Project
/// Import a mxd
Item mxdToImport = ItemFactory.Instance.Create(@"C:\Projects\RegionalSurvey\LatestResults.mxd");
var addedMxd = await QueuedTask.Run(
() => Project.Current.AddItem(mxdToImport as IProjectItem));
/// Add map package
Item mapPackageToAdd = ItemFactory.Instance.Create(@"c:\Data\Map.mpkx");
var addedMapPackage = await QueuedTask.Run(
() => Project.Current.AddItem(mapPackageToAdd as IProjectItem));
/// Add an exported Pro map
Item proMapToAdd = ItemFactory.Instance.Create(@"C:\ExportedMaps\Election\Districts.mapx");
var addedMapProjectItem = await QueuedTask.Run(
() => Project.Current.AddItem(proMapToAdd as IProjectItem));
Create An Item
Item mxdItem = ItemFactory.Instance.Create(@"C:\Projects\RegionalSurvey\LatestResults.mxd");
Create A PortalItem
// Creates an Item from an existing portal item base on its ID
string portalItemID = "9801f878ff4a22738dff3f039c43e395";
Item portalItem = ItemFactory.Instance.Create(portalItemID, ItemFactory.ItemType.PortalItem);
Create A PortalFolder
// Creates an Item from an existing portal folder base on its ID
string portalFolderID = "39c43e39f878f4a2279838dfff3f0015";
Item portalFolder = ItemFactory.Instance.Create(portalFolderID, ItemFactory.ItemType.PortalFolderItem);
Item: Copy metadata from the source item's metadata: CopyMetadataFromItem
Item featureClassItem = ItemFactory.Instance.Create(@"C:\projectAlpha\GDBs\regionFive.gdb\SourceFeatureClass");
await QueuedTask.Run(() => metadataItemImport.CopyMetadataFromItem(featureClassItem));
Item: Delete certain content from the metadata of the current item: DeleteMetadataContent
Item featureClassWithMetadataItem = ItemFactory.Instance.Create(@"C:\projectBeta\GDBs\regionFive.gdb\SourceFeatureClass");
//Delete thumbnail content from item's metadata
await QueuedTask.Run(() => featureClassWithMetadataItem.DeleteMetadataContent(MDDeleteContentOption.esriMDDeleteThumbnail));
Import a pagx into a project
//Import a pagx into a project.
//Create a layout project item from importing a pagx file
await QueuedTask.Run(() =>
{
IProjectItem pagx = ItemFactory.Instance.Create(
@"C:\Temp\Layout.pagx") as IProjectItem;
Project.Current.AddItem(pagx);
});
Import a report file
//Note: Call within QueuedTask.Run()
Item reportToImport = ItemFactory.Instance.Create(reportFile);
Project.Current.AddItem(reportToImport as IProjectItem);
EsriHttpClient: Get a Service Layer and Add it to Pro
UriBuilder searchURL = new UriBuilder(ArcGISPortalManager.Current.GetActivePortal().PortalUri)
{
Path = "sharing/rest/search"
};
string layers = "(type:\"Map Service\" OR type:\"Image Service\" OR type:\"Feature Service\" OR type:\"WMS\" OR type:\"KML\")";
//any public layer content
searchURL.Query = string.Format("q={0}&f=json", layers);
EsriHttpClient httpClient = new EsriHttpClient();
var searchResponse = httpClient.Get(searchURL.Uri.ToString());
dynamic resultItems = JObject.Parse(await searchResponse.Content.ReadAsStringAsync());
long numberOfTotalItems = resultItems.total.Value;
if (numberOfTotalItems == 0)
return;
List<dynamic> resultItemList = new List<dynamic>();
resultItemList.AddRange(resultItems.results);
//get the first result
dynamic item = resultItemList[0];
string itemID = item.id;
Item currentItem = ItemFactory.Instance.Create(itemID, ItemFactory.ItemType.PortalItem);
await QueuedTask.Run(() =>
{
//Create a LayerCreationParam
var layerParam = new LayerCreationParams(currentItem);
// if we have an item that can be turned into a layer
// add it to the map
if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParam, MapView.Active.Map);
});
Target Platforms: Windows 11, Windows 10, Windows 8.1