ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Core Namespace / ItemFactory Class / Create Method
The full path to the item on disk or portal item identifier for a resource that will be created
(optional) The type of item that is expected to be created, as specified by ItemFactory.ItemType. (default value = PathItem)
Example

In This Topic
    Create Method (ItemFactory)
    In This Topic
    Creates a Item representing the resource identified by the Uri
    Syntax
    Public Function Create( _
       ByVal uri As String, _
       Optional ByVal itemType As ItemFactory.ItemType _
    ) As Item

    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
    Exceptions
    ExceptionDescription
    Thrown when a method is called on the wrong Pro thread
    Remarks
    Items stored on a local or network computer are identified as "PathItem". The path can point to a mapx, mxd, sxd, tbx, and so forth. The item factory creates a Item for all of these file types.
    Items available from the active portal are identified as either "PortalItem" or "PortalFolderItem". The Uri must be the item id and can point to portal or online content. The item's portal or online is assumed to be the active portal. If there is no active portal or the item's portal (or online if it is in online) is not the active portal then the Create will fail and null will be returned. Portal items can be cast to ArcGIS.Desktop.Core.Portal.PortalItem
    Note: To access a folder of items available from the active portal, the folder's portal identifier must be provided as the Uri. The folder's portal is assumed to be the active portal same as for creating portal items. Portal folders can be cast to ArcGIS.Desktop.Core.Portal.PortalFolder
    Items stored on an external cloud platform besides Portal are identified as "CloudItem". The path can point to a dwg, dgn, dxf, rvt, and so on. The item factory creates a Item for all of these file types.
    Items, once created by the factory, can be added to the project using Project.AddItem. Adding a file item or portal item to the project creates a project item that lives in the current project (eg a map, a scene, a layout, a style, a database connection, etc.). When you share that project you likewise share its project items. Project item derived types all contain "ProjectItem" in their name (MapProjectItem, StyleProjectItem, FolderConnectionProjectItem, etc.). All project items implement IProjectItem.
    Some items, can be imported to a project. In certain cases, importing items into a project can (but not always) result in more than one project item being added. The canonical example being an mxd which can result in a map and a layout being added. Therefore, items that support being imported, implement IProjectMultiItem and can be passed to the Project.ImportItem method (in addition to Project.AddItem - which all items support). This is useful if you want a reference to the imported project item(s) directly (rather than going to Project "Getitems" to retrieve it after it has been added). Test the returned Item from ItemFactory Create for the presence of IProjectMultiItem to see if the given item can use the ImportItem method.
    Note: When enumerating folder content (i.e. a FolderConnectionProjectItem) in the API (via a "GetItems" call), the Items returned will be file item or "PathItem" "Item" types (whether mapx, mdxs, sxds, etc.). They are the same "Item" as would be created via a call to ItemFactory Create using their path as the uri. They are not treated differently.
    Note: Items should be created on a QueuedTask.
    Example
    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);
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also