Click or drag to resize

PortalItemCreateAsync Method (Uri, Credential)

Creates a portal item object from a portal item Url.

Namespace:  Esri.ArcGISRuntime.Portal
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.11.0
public static Task<PortalItem> CreateAsync(
	Uri url,
	Credential credential = null


Type: SystemUri
The Url of the portal item.
credential (Optional)
Type: Esri.ArcGISRuntime.SecurityCredential
The security credential.

Return Value

Type: TaskPortalItem
The task object representing the asynchronous create operation. The value of the task result is a PortalItem object.


Example Name: ListRelatedFeatures

List features related to the selected feature.

Code example screen shot.

// Copyright 2018 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Portal;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Windows;

namespace ArcGISRuntime.WPF.Samples.ListRelatedFeatures
        name: "List related features",
        category: "Data",
        description: "List features related to the selected feature.",
        instructions: "Click on a feature to select it. The related features will be displayed in a list.",
        tags: new[] { "features", "identify", "query", "related", "relationship", "search" })]
    public partial class ListRelatedFeatures
        // Hold the URL of the web map.
        private readonly Uri _mapUri =
            new Uri("");

        // Reference to the feature layer.
        private FeatureLayer _myFeatureLayer;

        public ListRelatedFeatures()

            // Create the UI, setup the control references and execute initialization.

        private async void Initialize()
                // Create the portal item from the URL to the webmap.
                PortalItem alaskaPortalItem = await PortalItem.CreateAsync(_mapUri);

                // Create the map from the portal item.
                Map myMap = new Map(alaskaPortalItem);

                // Add the map to the mapview.
                MyMapView.Map = myMap;

                // Wait for the map to load.
                await myMap.LoadAsync();

                // Get the feature layer from the map.
                _myFeatureLayer = (FeatureLayer) myMap.OperationalLayers.First();

                // Wait for the layer to load.
                await _myFeatureLayer.LoadAsync();

                // Make the selection color yellow.
                MyMapView.SelectionProperties.Color = Color.Yellow;

                // Listen for GeoViewTapped events.
                MyMapView.GeoViewTapped += MyMapViewOnGeoViewTapped;

                // Hide the loading indicator.
                LoadingProgress.Visibility = Visibility.Collapsed;
            catch (Exception e)
                MessageBox.Show(e.ToString(), "Error");

        private async void MyMapViewOnGeoViewTapped(object sender, GeoViewInputEventArgs e)
            // Clear any existing feature selection and results list.
            MyResultsView.ItemsSource = null;

                // Identify the tapped feature.
                IdentifyLayerResult results = await MyMapView.IdentifyLayerAsync(_myFeatureLayer, e.Position, 10, false);

                // Return if there are no results.
                if (results.GeoElements.Count < 1)

                // Show the loading indicator (this can take a while).
                LoadingProgress.Visibility = Visibility.Visible;

                // Get the first result.
                ArcGISFeature myFeature = (ArcGISFeature) results.GeoElements.First();

                // Select the feature.

                // Get the feature table for the feature.
                ArcGISFeatureTable myFeatureTable = (ArcGISFeatureTable) myFeature.FeatureTable;

                // Query related features.
                IReadOnlyList<RelatedFeatureQueryResult> relatedFeaturesResult =
                    await myFeatureTable.QueryRelatedFeaturesAsync(myFeature);

                // Create a list to hold the formatted results of the query.
                List<string> queryResultsForUi = new List<string>();

                // For each query result.
                foreach (RelatedFeatureQueryResult result in relatedFeaturesResult)
                    // And then for each feature in the result.
                    foreach (Feature resultFeature in result)
                        // Get a reference to the feature's table.
                        ArcGISFeatureTable relatedTable = (ArcGISFeatureTable) resultFeature.FeatureTable;

                        // Get the display field name - this is the name of the field that is intended for display.
                        string displayFieldName = relatedTable.LayerInfo.DisplayFieldName;

                        // Get the name of the feature's table.
                        string tableName = relatedTable.TableName;

                        // Get the display name for the feature.
                        string featureDisplayname = resultFeature.Attributes[displayFieldName].ToString();

                        // Create a formatted result string.
                        string formattedResult = string.Format("{0} - {1}", tableName, featureDisplayname);

                        // Add the result to the list.

                // Update the UI with the result list.
                MyResultsView.ItemsSource = queryResultsForUi;

                // Hide the loading indicator.
                LoadingProgress.Visibility = Visibility.Collapsed;
            catch (Exception ex)
                MessageBox.Show(ex.ToString(), "Error");
<UserControl x:Class="ArcGISRuntime.WPF.Samples.ListRelatedFeatures.ListRelatedFeatures"
        <esri:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
                <TextBlock Text="Tap a park (green) to see related features."
                           TextAlignment="Center" FontWeight="SemiBold"
                           Margin="0,0,0,10" />
                <ProgressBar x:Name="LoadingProgress"
                             Margin="0,0,0,10" Visibility="Visible" />
                <ListView x:Name="MyResultsView"
                            <TextBlock Text="{Binding}" TextWrapping="Wrap" />
                        <Style TargetType="ListViewItem">
                            <Setter Property="Focusable" Value="false"/>
See Also
Additional Examples
Hyperlink to ExampleDescription
ListRelatedFeaturesList features related to the selected feature.