ArcGIS Runtime SDK for WPF - Library Reference
GetItemsAsync Method
See Also  Example
ESRI.ArcGIS.Client.Portal Namespace > ArcGISPortalFolder Class : GetItemsAsync Method

callback
The callback executed when the result is available.
Gets the items of the user that are stored in this folder.

Syntax

Visual Basic (Declaration) 
Public Sub GetItemsAsync( _
   ByVal callback As Action(Of IEnumerable(Of ArcGISPortalItem),Exception) _
) 
C# 
public void GetItemsAsync( 
   Action<IEnumerable<ArcGISPortalItem>,Exception> callback
)

Remarks

The purpose of this Method is to obtain Portal.ArcGISPortalItems that belong to a particular authenticated user for nested sub-folders in their ArcGIS Online (AGOL) and ArcGIS Portal account. This method performs an asynchronous request to obtain an IEnumerable of Portal.ArcGISPortalItem objects for the credentialed logged in user via the IdentityManager. You cannot use anonymous access to obtain a Portal.ArcGISPortalFolder object and use this Method to obtain valid results. As AGOL/ArcGIS Portal require the use of long term tokens to access secured user information, you should remember to set the IdentityManager.TokenGenerationReferer Property to the correct string required by your development platform.

It is a recommended best practice to call the Portal.ArcGISPortal.InitializeAsync Method to initialize the Portal.ArcGISPortal object such that the credentialed Portal.ArcGISPortal.CurrentUser can be obtained. Then for the credentialed user, call the Portal.ArcGISPortalUser.GetFoldersAsync Method to obtain an IEnumerable of Portal.ArcGISPortalFolder objects for which this Method can be used. It is not recommended to try an obtain Portal.ArcGISPortalUser objects via the following Methods and Properties, because the returned users are not authenticated credentialed users and you will not be able to obtain sub-folder information: Portal.ArcGISPortal.SearchUsersAsync, Portal.ArcGISPortalGroup.GetGroupUsersAsync, and Portal.ArcGISPortalInfo.QueryUsersAsync.

To obtain Portal.ArcGISPortalItem objects that exist at the root level of the user account on AGOL/ArcGIS Portal use the Portal.ArcGISPortalUser.GetItemsAsync Method.

Parameters

callback
The callback executed when the result is available.

Example

How to use:

Set the correct values for the example code initialization variables in the code-behind (the user needs to provide the ArcGIS Online (AGOL) or ArcGIS Portal base Url and credentials via username/password to access secured services). Once the user information is provided: click the button to make Asynchronous calls to the AGOL/ArcGIS Portal server to retrieve the names of the folders the user has content stored in. Then click on a folder name to display detailed ArcGISPortalItem information.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Using the ArcGISPortalFolders.GetItemsAsync to get ArcGISPortalItem details.

XAMLCopy Code
<Grid x:Name="LayoutRoot" Background="White">
  
  <!-- Get the ArcGIS Online/ArcGIS Portal base Url. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,83,0,0" Name="Label_ArcGISPortalBaseUrl" VerticalAlignment="Top" 
       Width="231" Content="ArcGIS Online or ArcGIS Portal base Url:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="239,79,0,0" Name="TextBox_ArcGISPortalBaseUrl" VerticalAlignment="Top" 
           Width="536" />
  
  <!-- Use the IdentityManager with user credentials to access the information for the ArcGISPortalUser. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,112,0,0" Name="Label_UserName" VerticalAlignment="Top" Width="70" 
       Content="UserName:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="77,108,0,0" Name="TextBox_UserName" VerticalAlignment="Top" Width="210" />
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="296,109,0,0" Name="Label_Password" VerticalAlignment="Top" Width="56" 
       Content="Password:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="355,108,0,0" Name="TextBox_Password" VerticalAlignment="Top" Width="210" />
  
  <!-- Button to invoke searching for folders (that contain ArcGISPortalItems) available on ArcGIS Online/ArcGIS Portal for the user. -->
  <Button Content="Get ArcGIS Portal Folder(s) that a user has content in on AGOL/ArcGIS Portal" Height="23" HorizontalAlignment="Left" 
          Margin="12,143,0,0" Name="Button1" VerticalAlignment="Top" Width="763" Click="Button1_Click" />
  
  <!-- Display the generic ArcGISPortal results to the user. -->
  <sdk:Label HorizontalAlignment="Left" Margin="13,180,0,392" Name="Label_GenericInfo" Width="202" 
       Content="Generic ArcGIS Portal Information:" VerticalAlignment="Top"/>
  <TextBlock Height="227" HorizontalAlignment="Left" Margin="12,203,0,0" Name="TextBlock_GenericInfo" VerticalAlignment="Top" Width="314" />
  
  <!--Display the Folder names the user has content in on the AGOL/ArcGIS Portal site. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,451,0,0" Name="Label_Folders" VerticalAlignment="Top" 
       Width="203" Content="Folders: [Click on a folder name]"/>
  <ListBox Height="118" HorizontalAlignment="Left" Margin="13,470,0,0" Name="ListBox_Folders" VerticalAlignment="Top" 
           Width="313" SelectionChanged="ListBox_Folders_SelectionChanged"/>
  
  <!-- Display detailed ArcGISPortalItem information. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="331,180,0,0" Name="Label_ItemInfo" VerticalAlignment="Top" Width="194" 
       Content="ArcGIS Portal Item Information:"/>
  <ListBox Height="385" HorizontalAlignment="Left" Margin="331,203,0,0" Name="ListBox_ItemInfo" VerticalAlignment="Top" Width="444" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="73" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="788" 
   TextWrapping="Wrap" Text="Set the correct values for the example code initialization variables in the code-behind (the user needs to 
   provide the ArcGIS Online (AGOL) or ArcGIS Portal base Url and credentials via username/password to access secured services). Once 
   the user information is provided: click the button to make Asynchronous calls to the AGOL/ArcGIS Portal server to retrieve the names of 
   the folders the user has content stored in. Then click on a folder name to display detailed ArcGISPortalItem information." />
  
</Grid>
C#Copy Code
public MainPage()
{
  InitializeComponent();
  
  // TODO: Provide your default values to run the example code.
  // ==========================================================
  
  // Provide the Url to ArcGIS OnLine (AGOL) or your ArcGIS Portal.
  TextBox_ArcGISPortalBaseUrl.Text = "http://www.arcgis.com";
  
  // To gain access to secured services on AGOL/Portal provide Username/Password information.
  TextBox_UserName.Text = "YourUserName";
  TextBox_Password.Text = "YourPassword";
}
            
// Member (i.e. Global) variables used later in the example code.
public ESRI.ArcGIS.Client.Portal.ArcGISPortalUser _MyCurrentUser;
public System.Collections.Generic.Dictionary<string, FolderHolder> _MyFolderHolderDictionary = new System.Collections.Generic.Dictionary<string, FolderHolder>();
            
// A helper class to store information about sub-folders found on the AGOL/ArcGIS Portal for the logged in user.
public class FolderHolder
{
  public string FolderTitle;
  public ESRI.ArcGIS.Client.Portal.ArcGISPortalFolder TheFolder;
}
            
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // This sub-routine executes when the user clicks the Button. The purpose is to get general information about the
  // AGOL/Portal service. Additionally, information about ArcGISPortalItems that belong to the user based upon their 
  // folder location in AGOL/ArcGIS Portal is returned. 
  
  // Clear out any existing results before proceeding.
  TextBlock_GenericInfo.Text = "";
  ListBox_Folders.Items.Clear();
  ListBox_ItemInfo.Items.Clear();
  _MyFolderHolderDictionary.Clear();
  
  // Set the referer string of the IdentityManager using the .TokenGenrationReferer Property. 
  // This will establish the referer string that is part of the Http WebRequest Header.
  // FYI: You can view the 'Referer' header information in freeware/shareware applications like 'Fiddler'.
  // NOTE: 
  // For WPF this value could be any string. 
  //   Ex: "http://www.MyWebSite.com", "http", "h", "Whatever".
  // For Silverlight this value should point to the .xap file, but any sub-string will do. 
  //   Ex: "http://localhost:65121/ClientBin/SL-App.xap", "http", "h". 
  // For Windows Phone this value should point to the application install location on the device, but any sub-string will do. 
  //   Ex: "file://Applications/Install/868A84BA-237D-4980-BF51-74E193CECCF1/Install/", "file", "f".
  ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions myGenerateTokenOptions = null;
  myGenerateTokenOptions = new ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions();
  myGenerateTokenOptions.Referer = "h";
  
  // Get the base Url for AGOL/Portal.
  string myArcGISPortalBaseUrl = TextBox_ArcGISPortalBaseUrl.Text;
  
  // Get the Username/Password for accessing secured AGOL/Portal services.
  string myUserName = TextBox_UserName.Text;
  string myPassword = TextBox_Password.Text;
  
  // Use IdentityManager to access secured AGOL/Portal services. This will cause an asynchronous call to the 
  // sub-routine called CALLBACK_IdentityManager_GenerateCredentialAsync. 
  ESRI.ArcGIS.Client.IdentityManager.Current.GenerateCredentialAsync(myArcGISPortalBaseUrl, myUserName, myPassword, CALLBACK_IdentityManager_GenerateCredentialAsync, myGenerateTokenOptions);
}
            
private void CALLBACK_IdentityManager_GenerateCredentialAsync(ESRI.ArcGIS.Client.IdentityManager.Credential myCredential, System.Exception ex)
{
  // This sub-routine executes as a result of the IdentityManager.GenerateCredentialAsync Method. 
  
  // Ensure there was not a problem in the returned results.
  if (ex == null)
  {
    // Create a new instance of the ArcGISPortal Class.
    ESRI.ArcGIS.Client.Portal.ArcGISPortal myArcGISPortal = new ESRI.ArcGIS.Client.Portal.ArcGISPortal();
    
    // Set the ArcGISPortal.Token Property to the IdentityManager.Credential long term token. Long term tokens are 
    // necessary to access secured AGOL/Portal services. 
    myArcGISPortal.Token = myCredential.Token;
    
    // Get the base Url of the AGOL/portal site.
    string myArcGISPortalBaseUrl = TextBox_ArcGISPortalBaseUrl.Text;
    
    // Add the other necessary parts to the base Url string so that information can be accessed on AGOL/Portal.
    string myArcGISPortalEnhancedUrl = myArcGISPortalBaseUrl + "/sharing/rest";
    
    // Make an asynchronous call to obtain information from AGOL/Portal. Upon successful completion of this call
    // you can then gain access to deeper levels of information using other ArcGISPortal asynchronous calls like:
    // .SearchGroupsAsync, .SearchItemsAsnyc, and .SearchUsersAsync. Additionally, you could also get Property 
    // information from the returned ArcGISPortal object for things like: .ArcGISPortalInfo and .CurrentUser 
    // which is a gateway to getting lots of other detailed information on AGOL/Portal. 
    myArcGISPortal.InitializeAsync(myArcGISPortalEnhancedUrl, CALLBACK_Portal_InitializeAsync);
  }
  else
  {
    // There was some problem with the IdentityManager.GenerateCredentialAsync call. Display the message to the user.
    MessageBox.Show("Could not log in. Please check credentials.");
  }
}
            
private void CALLBACK_Portal_InitializeAsync(ESRI.ArcGIS.Client.Portal.ArcGISPortal myArcGISPortal, System.Exception ex)
{
  // This sub-routine executes as a result of the ArcGISPortal.InitializeAsync Method. 
  
  // Ensure there was not a problem in the returned results.
  if (ex == null)
  {
    // Get the ArcGISPortalInfo object from ArcGISPortal. 
    ESRI.ArcGIS.Client.Portal.ArcGISPortalInfo myArcGISPortalInfo = myArcGISPortal.ArcGISPortalInfo;
    
    // Get the ArcGISPortalInfo.PortalHostname information.
    string myPortalHostName = "";
    if (myArcGISPortalInfo != null)
    {
      myPortalHostName = myArcGISPortalInfo.PortalHostname;
    }
    
    // Get the ArcGISPortal.CurrentUser object. Initialize some string variables for the username and email of the
    // CurrentUser. 
    _MyCurrentUser = myArcGISPortal.CurrentUser; // NOTE: We are setting a Member (i.e. Global) variable!
    string myUserName = _MyCurrentUser.UserName;
    string myEmail = _MyCurrentUser.Email;
    
    // Get the CurrentVerion of the AGOL/Portal server.
    string myCurrentVersion = myArcGISPortal.CurrentVersion;
    
    // Get the Url of the AGOL/Portal server.
    string myUrl = myArcGISPortal.Url;
    
    // Create a StringBuilder class to hold information obtained from the AGOL/Portal service.
    System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder();
    myStringBuilder.Append("ArcGISPortalInfo.PortalHostName: " + Environment.NewLine + myPortalHostName + Environment.NewLine + Environment.NewLine);
    myStringBuilder.Append("ArcGISPortal.CurrentVersion: " + Environment.NewLine + myCurrentVersion + Environment.NewLine + Environment.NewLine);
    myStringBuilder.Append("ArcGISPortal.Url: " + Environment.NewLine + myUrl + Environment.NewLine + Environment.NewLine);
    myStringBuilder.Append("CurrentUser.UserName: " + Environment.NewLine + myUserName + Environment.NewLine + Environment.NewLine);
    myStringBuilder.Append("CurrentUser.Email: " + Environment.NewLine + myEmail + Environment.NewLine + Environment.NewLine);
    
    // Display the information about the AGOL/Portal server to the user.
    TextBlock_GenericInfo.Text = myStringBuilder.ToString();
    
    //----------------------------------------------------------------
    
    // For the logged in user, display the folder structure for their AGOL/ArcGIS Portal account. The user will then need to 
    // click on a particular folder name in the ListBox_Folders to display details of the ArcGISPortalItems in that folder.
    
    // Every user has a root folder.
    ListBox_Folders.Items.Add("Root Folder");
    
    // Display any sub-folders if they have been created by the user. 
    _MyCurrentUser.GetFoldersAsync(CALLBACK_ArcGISPortalUser_GetFoldersAsync);
    
  }
  else
  {
    // There was some problem with the ArcGISPortal.InitializeAsync call. Display the message to the user.
    MessageBox.Show("Failed to initialize" + ex.Message.ToString());
  }
}
            
private void CALLBACK_ArcGISPortalUser_GetFoldersAsync(IEnumerable<ESRI.ArcGIS.Client.Portal.ArcGISPortalFolder> IEnumberableOfArcGISPortalFolder, System.Exception ex)
{
  // This sub-routine executes as a result of the ArcGISPortalUser.GetFolderssAsync Method. The purpose is to display the 
  // sub-folder structures available in the AGOL/ArcGIS Portal account for the logged in user.  
  
  // Ensure there was not a problem in the returned results.
  if (ex == null)
  {
    // Only the valid user found via the IdentityManager will have results. Users that cannot be found via IdentityManager 
    // will come back as Nothing/null and you will need to handle accordingly.
    if (IEnumberableOfArcGISPortalFolder != null)
    {
      // Loop through each ArcGISPortalFolder object.
      foreach (ESRI.ArcGIS.Client.Portal.ArcGISPortalFolder oneArcGISPortalFolder in IEnumberableOfArcGISPortalFolder)
      {
        // Create a new instance of the helper class FolderHolder object. This will store information about user account sub-folders
        // for use later when the user clicks on the name of the folder in the ListBox_Folders.
        FolderHolder myFolderHolder = new FolderHolder();
        myFolderHolder.FolderTitle = oneArcGISPortalFolder.Title;
        myFolderHolder.TheFolder = oneArcGISPortalFolder;
        
        // Add a single FolderHolder object into the FolderHolderDictionary. The dictionary key is the human readable folder name.
        _MyFolderHolderDictionary.Add(myFolderHolder.FolderTitle, myFolderHolder); // NOTE: We are setting a Member (i.e. Global) variable!
        
        // Add the human readable folder name to the ListBox_Folders.
        ListBox_Folders.Items.Add(myFolderHolder.FolderTitle);
      }
    }
  }
  else
  {
    // There was some problem with the ArcGISPortalUser.GetFoldersAsync call. Display the message to the user.
    MessageBox.Show("Failed to initialize" + ex.Message.ToString());
  }
}
            
private void ListBox_Folders_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
  // This sub-routine runs when the user clicks on the name of a folder in the ListBox_Folders control.
  
  // Clear out any existing results in case the user clicks multiple folders to get ArcGISPortalItem information.
  ListBox_ItemInfo.Items.Clear();
  
  // Create a local variable for the sender (which is the ListBox_Folders).
  ListBox myListBox = (ListBox)sender;
  
  // Only perform functions if we have a folder to click on. 
  if (myListBox.Items.Count > 0)
  {
    // Get the human readable folder name.
    string mySelectedItem = myListBox.SelectedItem.ToString();
    
    if (mySelectedItem == "Root Folder")
    {
      // The user wants information for the root level folder on the AGOL/ArcGIS Portal account. 
      
      // Use the ArcGISPortalUser.GetItemsAsync Method to display ArcGISPortalItems found.
      _MyCurrentUser.GetItemsAsync(CALLBACK_GetItemsAsync);
    }
    else
    {
      // The user wants information for a sub-level folder on the AGOL/ArcGIS Portal account. 
      
      // Get a FolderHolder object from the MyFolderHolderDictionay object based upon the human readable sub-folder name.
      FolderHolder myFolderHolder = _MyFolderHolderDictionary[mySelectedItem];
      
      // Get the ArcGISPortalFolder object.
      ESRI.ArcGIS.Client.Portal.ArcGISPortalFolder oneArcGISPortalFolder = myFolderHolder.TheFolder;
      
      // Use the ArcGISPortalFolder.GetItemsAsync Method to display ArcGISPortalItems found.
      oneArcGISPortalFolder.GetItemsAsync(CALLBACK_GetItemsAsync);
    }
  }
}
            
private void CALLBACK_GetItemsAsync(IEnumerable<ESRI.ArcGIS.Client.Portal.ArcGISPortalItem> IEnumberableOfArcGISPortalItem, System.Exception ex)
{
  // This sub-routine executes as a result of the ArcGISPortalUser.GetItemsAsync Method and ArcGISPortalFolder.GetItemsAsync Method.
  // This one sub-routine will handle getting ArGISPortalItem information and display it to the user in the ListBox_ItemInfo.
  
  // Ensure there was not a problem in the returned results.
  if (ex == null)
  {
    // Only the valid user found via the IdentityManager will have results. Users that cannot be found via IdentityManager 
    // will come back as Nothing/null and you will need to handle accordingly.
    if (IEnumberableOfArcGISPortalItem != null)
    {
      // Create a StringBuilder class to hold User information obtained from the AGOL/Portal service. Display the 
      // number of Items found in the ListBox.
      System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder();
      myStringBuilder.Append("Number of ArcGIS Portal Items: " + IEnumberableOfArcGISPortalItem.Count().ToString() + Environment.NewLine);
      ListBox_ItemInfo.Items.Add(myStringBuilder.ToString());
      
      // Loop through each ArcGISPortalItem object.
      foreach (ESRI.ArcGIS.Client.Portal.ArcGISPortalItem oneArcGISPortalItem in IEnumberableOfArcGISPortalItem)
      {
        // Get various ArcGISPortalItem Property information; like: the Title of the Item, the long GUID type of Id for 
        // the Item, the access level (ex: Private, Public, Organization, etc.) of the Item, and the type of Item it is 
        // (ex: shapefile, webmap, .csv file, etc.).
        ESRI.ArcGIS.Client.Portal.PortalAccess myPortalAccess = oneArcGISPortalItem.Access;
        string myTitle = oneArcGISPortalItem.Title;
        string myId = oneArcGISPortalItem.Id;
        string myTypeName = oneArcGISPortalItem.TypeName;
        
        // Create a new StackPanel to house the information that will be displayed to the user about each Item found.
        StackPanel myStackPanel = new StackPanel();
        myStackPanel.Orientation = Orientation.Vertical;
        
        // Display the title of the Item. 
        TextBlock myTextBlock_ArcGISPortalItem_Title = new TextBlock();
        myTextBlock_ArcGISPortalItem_Title.Text = "ArcGISPortalItem.Title: " + myTitle;
        myStackPanel.Children.Add(myTextBlock_ArcGISPortalItem_Title);
        
        // Display the long GUID type of Id for the Item.
        TextBlock myTextBlock_ArcGISPortalItem_Id = new TextBlock();
        myTextBlock_ArcGISPortalItem_Id.Text = "ArcGISPortalItem.Id: " + myId;
        myStackPanel.Children.Add(myTextBlock_ArcGISPortalItem_Id);
        
        // Display the access level for the Item (ex: Private, Public, Organization, etc.).
        TextBlock myTextBlock_ArcGISPortalItem_PortalAccess = new TextBlock();
        myTextBlock_ArcGISPortalItem_PortalAccess.Text = "ArcGISPortalItem.PortalAccess: " + myPortalAccess.ToString();
        myStackPanel.Children.Add(myTextBlock_ArcGISPortalItem_PortalAccess);
        
        // Display the type of Item it is (ex: shapefile, webmap, .csv file, etc.).  
        TextBlock myTextBlock_ArcGISPortalItem_TypeName = new TextBlock();
        myTextBlock_ArcGISPortalItem_TypeName.Text = "ArcGISPortalItem.TypeName: " + myTypeName;
        myStackPanel.Children.Add(myTextBlock_ArcGISPortalItem_TypeName);
        
        // Add the various display objects about the User in the ListBox.
        ListBox_ItemInfo.Items.Add(myStackPanel);
      }
    }
  }
  else
  {
    // There was some problem with the ArcGISPortalUser.GetItemsAsync or ArcGISPortalFolder.GetItemsAsync call. Display the message to the user.
    MessageBox.Show("Failed to initialize" + ex.Message.ToString());
  }
}
VB.NETCopy Code
Public Sub New()
  InitializeComponent()
  
  ' TODO: Provide your default values to run the example code.
  ' ==========================================================
  
  ' Provide the Url to ArcGIS OnLine (AGOL) or your ArcGIS Portal.
  TextBox_ArcGISPortalBaseUrl.Text = "http://www.arcgis.com"
  
  ' To gain access to secured services on AGOL/Portal provide Username/Password information.
  TextBox_UserName.Text = "YourUserName"
  TextBox_Password.Text = "YourPassword"
  
End Sub
            
' Member (i.e. Global) variables used later in the example code.
Public _MyCurrentUser As ESRI.ArcGIS.Client.Portal.ArcGISPortalUser
Public _MyFolderHolderDictionary As New System.Collections.Generic.Dictionary(Of String, FolderHolder)
            
' A helper class to store information about sub-folders found on the AGOL/ArcGIS Portal for the logged in user.
Public Class FolderHolder
  Public FolderTitle As String
  Public TheFolder As ESRI.ArcGIS.Client.Portal.ArcGISPortalFolder
End Class
            
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' This sub-routine executes when the user clicks the Button. The purpose is to get general information about the
  ' AGOL/Portal service. Additionally, information about ArcGISPortalItems that belong to the user based upon their 
  ' folder location in AGOL/ArcGIS Portal is returned. 
  
  ' Clear out any existing results before proceeding.
  TextBlock_GenericInfo.Text = ""
  ListBox_Folders.Items.Clear()
  ListBox_ItemInfo.Items.Clear()
  _MyFolderHolderDictionary.Clear()
  
  ' Set the referer string of the IdentityManager using the .TokenGenrationReferer Property. 
  ' This will establish the referer string that is part of the Http WebRequest Header.
  ' FYI: You can view the 'Referer' header information in freeware/shareware applications like 'Fiddler'.
  ' NOTE: 
  ' For WPF this value could be any string. 
  '   Ex: "http://www.MyWebSite.com", "http", "h", "Whatever".
  ' For Silverlight this value should point to the .xap file, but any sub-string will do. 
  '   Ex: "http://localhost:65121/ClientBin/SL-App.xap", "http", "h". 
  ' For Windows Phone this value should point to the application install location on the device, but any sub-string will do. 
  '   Ex: "file://Applications/Install/868A84BA-237D-4980-BF51-74E193CECCF1/Install/", "file", "f".
  Dim myGenerateTokenOptions As ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions
  myGenerateTokenOptions = New ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions
  myGenerateTokenOptions.Referer = "h"
  
  ' Get the base Url for AGOL/Portal.
  Dim myArcGISPortalBaseUrl As String = TextBox_ArcGISPortalBaseUrl.Text
  
  ' Get the Username/Password for accessing secured AGOL/Portal services.
  Dim myUserName As String = TextBox_UserName.Text
  Dim myPassword As String = TextBox_Password.Text
  
  ' Use IdentityManager to access secured AGOL/Portal services. This will cause an asynchronous call to the 
  ' sub-routine called CALLBACK_IdentityManager_GenerateCredentialAsync. 
  ESRI.ArcGIS.Client.IdentityManager.Current.GenerateCredentialAsync(myArcGISPortalBaseUrl,
                                                                     myUserName,
                                                                     myPassword,
                                                                     AddressOf CALLBACK_IdentityManager_GenerateCredentialAsync,
                                                                     myGenerateTokenOptions)
  
End Sub
            
Private Sub CALLBACK_IdentityManager_GenerateCredentialAsync(myCredential As ESRI.ArcGIS.Client.IdentityManager.Credential,
                                                             ex As System.Exception)
  
  ' This sub-routine executes as a result of the IdentityManager.GenerateCredentialAsync Method. 
  
  ' Ensure there was not a problem in the returned results.
  If ex Is Nothing Then
    
    ' Create a new instance of the ArcGISPortal Class.
    Dim myArcGISPortal As ESRI.ArcGIS.Client.Portal.ArcGISPortal = New ESRI.ArcGIS.Client.Portal.ArcGISPortal
    
    ' Set the ArcGISPortal.Token Property to the IdentityManager.Credential long term token. Long term tokens are 
    ' necessary to access secured AGOL/Portal services. 
    myArcGISPortal.Token = myCredential.Token
    
    ' Get the base Url of the AGOL/portal site.
    Dim myArcGISPortalBaseUrl As String = TextBox_ArcGISPortalBaseUrl.Text
    
    ' Add the other necessary parts to the base Url string so that information can be accessed on AGOL/Portal.
    Dim myArcGISPortalEnhancedUrl As String = myArcGISPortalBaseUrl + "/sharing/rest"
    
    ' Make an asynchronous call to obtain information from AGOL/Portal. Upon successful completion of this call
    ' you can then gain access to deeper levels of information using other ArcGISPortal asynchronous calls like:
    ' .SearchGroupsAsync, .SearchItemsAsnyc, and .SearchUsersAsync. Additionally, you could also get Property 
    ' information from the returned ArcGISPortal object for things like: .ArcGISPortalInfo and .CurrentUser 
    ' which is a gateway to getting lots of other detailed information on AGOL/Portal. 
    myArcGISPortal.InitializeAsync(myArcGISPortalEnhancedUrl, AddressOf CALLBACK_Portal_InitializeAsync)
    
  Else
    
    ' There was some problem with the IdentityManager.GenerateCredentialAsync call. Display the message to the user.
    MessageBox.Show("Could not log in. Please check credentials.")
    
  End If
  
End Sub
            
Private Sub CALLBACK_Portal_InitializeAsync(myArcGISPortal As ESRI.ArcGIS.Client.Portal.ArcGISPortal, ex As System.Exception)
  
  ' This sub-routine executes as a result of the ArcGISPortal.InitializeAsync Method. 
  
  ' Ensure there was not a problem in the returned results.
  If ex Is Nothing Then
    
    ' Get the ArcGISPortalInfo object from ArcGISPortal. 
    Dim myArcGISPortalInfo As ESRI.ArcGIS.Client.Portal.ArcGISPortalInfo = myArcGISPortal.ArcGISPortalInfo
    
    ' Get the ArcGISPortalInfo.PortalHostname information.
    Dim myPortalHostName As String = ""
    If myArcGISPortalInfo IsNot Nothing Then
      myPortalHostName = myArcGISPortalInfo.PortalHostname
    End If
    
    ' Get the ArcGISPortal.CurrentUser object. Initialize some string variables for the username and email of the
    ' CurrentUser. 
    _MyCurrentUser = myArcGISPortal.CurrentUser ' NOTE: We are setting a Member (i.e. Global) variable!
    Dim myUserName As String = _MyCurrentUser.UserName
    Dim myEmail As String = _MyCurrentUser.Email
    
    ' Get the CurrentVerion of the AGOL/Portal server.
    Dim myCurrentVersion As String = myArcGISPortal.CurrentVersion
    
    ' Get the Url of the AGOL/Portal server.
    Dim myUrl As String = myArcGISPortal.Url
    
    ' Create a StringBuilder class to hold information obtained from the AGOL/Portal service.
    Dim myStringBuilder As New Text.StringBuilder
    myStringBuilder.Append("ArcGISPortalInfo.PortalHostName: " + vbCrLf + myPortalHostName + vbCrLf + vbCrLf)
    myStringBuilder.Append("ArcGISPortal.CurrentVersion: " + vbCrLf + myCurrentVersion + vbCrLf + vbCrLf)
    myStringBuilder.Append("ArcGISPortal.Url: " + vbCrLf + myUrl + vbCrLf + vbCrLf)
    myStringBuilder.Append("CurrentUser.UserName: " + vbCrLf + myUserName + vbCrLf + vbCrLf)
    myStringBuilder.Append("CurrentUser.Email: " + vbCrLf + myEmail + vbCrLf + vbCrLf)
    
    ' Display the information about the AGOL/Portal server to the user.
    TextBlock_GenericInfo.Text = myStringBuilder.ToString
    
    '----------------------------------------------------------------
    
    ' For the logged in user, display the folder structure for their AGOL/ArcGIS Portal account. The user will then need to 
    ' click on a particular folder name in the ListBox_Folders to display details of the ArcGISPortalItems in that folder.
    
    ' Every user has a root folder.
    ListBox_Folders.Items.Add("Root Folder")
    
    ' Display any sub-folders if they have been created by the user. 
    _MyCurrentUser.GetFoldersAsync(AddressOf CALLBACK_ArcGISPortalUser_GetFoldersAsync)
    
  Else
    
    ' There was some problem with the ArcGISPortal.InitializeAsync call. Display the message to the user.
    MessageBox.Show("Failed to initialize" + ex.Message.ToString())
    
  End If
  
End Sub
            
Private Sub CALLBACK_ArcGISPortalUser_GetFoldersAsync(IEnumberableOfArcGISPortalFolder As IEnumerable(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalFolder),
                                                      ex As System.Exception)
  
  ' This sub-routine executes as a result of the ArcGISPortalUser.GetFoldersAsync Method. The purpose is to display the 
  ' sub-folder structures available in the AGOL/ArcGIS Portal account for the logged in user.  
  
  ' Ensure there was not a problem in the returned results.
  If ex Is Nothing Then
    
    ' Only the valid user found via the IdentityManager will have results. Users that cannot be found via IdentityManager 
    ' will come back as Nothing/null and you will need to handle accordingly.
    If IEnumberableOfArcGISPortalFolder IsNot Nothing Then
      
      ' Loop through each ArcGISPortalFolder object.
      For Each oneArcGISPortalFolder As ESRI.ArcGIS.Client.Portal.ArcGISPortalFolder In IEnumberableOfArcGISPortalFolder
        
        ' Create a new instance of the helper class FolderHolder object. This will store information about user account sub-folders
        ' for use later when the user clicks on the name of the folder in the ListBox_Folders.
        Dim myFolderHolder As New FolderHolder
        myFolderHolder.FolderTitle = oneArcGISPortalFolder.Title
        myFolderHolder.TheFolder = oneArcGISPortalFolder
        
        ' Add a single FolderHolder object into the FolderHolderDictionary. The dictionary key is the human readable folder name.
        _MyFolderHolderDictionary.Add(myFolderHolder.FolderTitle, myFolderHolder) ' NOTE: We are setting a Member (i.e. Global) variable!
        
        ' Add the human readable folder name to the ListBox_Folders.
        ListBox_Folders.Items.Add(myFolderHolder.FolderTitle)
        
      Next
      
    End If
    
  Else
    
    ' There was some problem with the ArcGISPortalUser.GetFoldersAsync call. Display the message to the user.
    MessageBox.Show("Failed to initialize" + ex.Message.ToString())
    
  End If
  
End Sub
            
Private Sub ListBox_Folders_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
  
  ' This sub-routine runs when the user clicks on the name of a folder in the ListBox_Folders control.
  
  ' Clear out any existing results in case the user clicks multiple folders to get ArcGISPortalItem information.
  ListBox_ItemInfo.Items.Clear()
  
  ' Create a local variable for the sender (which is the ListBox_Folders).
  Dim myListBox As ListBox = sender
  
  ' Only perform functions if we have a folder to click on. 
  If myListBox.Items.Count > 0 Then
    
    ' Get the human readable folder name.
    Dim mySelectedItem As String = myListBox.SelectedItem.ToString
    
    If mySelectedItem = "Root Folder" Then
      
      ' The user wants information for the root level folder on the AGOL/ArcGIS Portal account. 
      
      ' Use the ArcGISPortalUser.GetItemsAsync Method to display ArcGISPortalItems found.
      _MyCurrentUser.GetItemsAsync(AddressOf CALLBACK_GetItemsAsync)
      
    Else
      
      ' The user wants information for a sub-level folder on the AGOL/ArcGIS Portal account. 
      
      ' Get a FolderHolder object from the MyFolderHolderDictionay object based upon the human readable sub-folder name.
      Dim myFolderHolder As FolderHolder = _MyFolderHolderDictionary.Item(mySelectedItem)
      
      ' Get the ArcGISPortalFolder object.
      Dim oneArcGISPortalFolder As ESRI.ArcGIS.Client.Portal.ArcGISPortalFolder = myFolderHolder.TheFolder
      
      ' Use the ArcGISPortalFolder.GetItemsAsync Method to display ArcGISPortalItems found.
      oneArcGISPortalFolder.GetItemsAsync(AddressOf CALLBACK_GetItemsAsync)
      
    End If
    
  End If
  
End Sub
            
Private Sub CALLBACK_GetItemsAsync(IEnumberableOfArcGISPortalItem As IEnumerable(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalItem),
                                   ex As System.Exception)
  
  ' This sub-routine executes as a result of the ArcGISPortalUser.GetItemsAsync Method and ArcGISPortalFolder.GetItemsAsync Method.
  ' This one sub-routine will handle getting ArGISPortalItem information and display it to the user in the ListBox_ItemInfo.
  
  ' Ensure there was not a problem in the returned results.
  If ex Is Nothing Then
    
    ' Only the valid user found via the IdentityManager will have results. Users that cannot be found via IdentityManager 
    ' will come back as Nothing/null and you will need to handle accordingly.
    If IEnumberableOfArcGISPortalItem IsNot Nothing Then
      
      ' Create a StringBuilder class to hold User information obtained from the AGOL/Portal service. Display the 
      ' number of Items found in the ListBox.
      Dim myStringBuilder As New Text.StringBuilder
      myStringBuilder.Append("Number of ArcGIS Portal Items: " + IEnumberableOfArcGISPortalItem.Count.ToString + vbCrLf)
      ListBox_ItemInfo.Items.Add(myStringBuilder.ToString)
      
      ' Loop through each ArcGISPortalItem object.
      For Each oneArcGISPortalItem As ESRI.ArcGIS.Client.Portal.ArcGISPortalItem In IEnumberableOfArcGISPortalItem
        
        ' Get various ArcGISPortalItem Property information; like: the Title of the Item, the long GUID type of Id for 
        ' the Item, the access level (ex: Private, Public, Organization, etc.) of the Item, and the type of Item it is 
        ' (ex: shapefile, webmap, .csv file, etc.).
        Dim myPortalAccess As ESRI.ArcGIS.Client.Portal.PortalAccess = oneArcGISPortalItem.Access
        Dim myTitle As String = oneArcGISPortalItem.Title
        Dim myId As String = oneArcGISPortalItem.Id
        Dim myTypeName As String = oneArcGISPortalItem.TypeName
        
        ' Create a new StackPanel to house the information that will be displayed to the user about each Item found.
        Dim myStackPanel As New StackPanel
        myStackPanel.Orientation = Orientation.Vertical
        
        ' Display the title of the Item. 
        Dim myTextBlock_ArcGISPortalItem_Title As New TextBlock
        myTextBlock_ArcGISPortalItem_Title.Text = "ArcGISPortalItem.Title: " + myTitle
        myStackPanel.Children.Add(myTextBlock_ArcGISPortalItem_Title)
        
        ' Display the long GUID type of Id for the Item.
        Dim myTextBlock_ArcGISPortalItem_Id As New TextBlock
        myTextBlock_ArcGISPortalItem_Id.Text = "ArcGISPortalItem.Id: " + myId
        myStackPanel.Children.Add(myTextBlock_ArcGISPortalItem_Id)
        
        ' Display the access level for the Item (ex: Private, Public, Organization, etc.).
        Dim myTextBlock_ArcGISPortalItem_PortalAccess As New TextBlock
        myTextBlock_ArcGISPortalItem_PortalAccess.Text = "ArcGISPortalItem.PortalAccess: " + myPortalAccess.ToString
        myStackPanel.Children.Add(myTextBlock_ArcGISPortalItem_PortalAccess)
        
        ' Display the type of Item it is (ex: shapefile, webmap, .csv file, etc.).  
        Dim myTextBlock_ArcGISPortalItem_TypeName As New TextBlock
        myTextBlock_ArcGISPortalItem_TypeName.Text = "ArcGISPortalItem.TypeName: " + myTypeName
        myStackPanel.Children.Add(myTextBlock_ArcGISPortalItem_TypeName)
        
        ' Add the various display objects about the User in the ListBox.
        ListBox_ItemInfo.Items.Add(myStackPanel)
        
      Next
      
    End If
    
  Else
    
    ' There was some problem with the ArcGISPortalUser.GetItemsAsync or ArcGISPortalFolder.GetItemsAsync call. Display the message to the user.
    MessageBox.Show("Failed to initialize" & ex.Message.ToString())
    
  End If
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8

See Also

© ESRI, Inc. All Rights Reserved.