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

searchParameters
The search parameters.
callback
The callback executed when the result is available.
Searchs users from a query string.

Syntax

Visual Basic (Declaration) 
Public Sub SearchUsersAsync( _
   ByVal searchParameters As SearchParameters, _
   ByVal callback As Action(Of SearchResultInfo(Of ArcGISPortalUser),Exception) _
) 

Remarks

This method obtains a Portal.SearchResultInfo<T> object that contains Portal.ArcGISPortalUser objects. Use the Portal.SearchResultInfo<T>.Results Property to get the IEnumberable collection of Portal.ArcGISPortalUser objects.

Portal.ArcGISPortalUser objects are user accounts within ArcGIS Online (AGOL) or ArcGIS Portal. Users add content to AGOL/ArcGIS Portal in the form of maps, tools, and applications. The Portal.ArcGISPortal.SearchUsersAsync Method allows searching for specific user accounts within ArcGIS Online (AGOL) or ArcGIS Portal. The Portal.ArcGISPortal.SearchUsersAsync Method requires providing specific Portal.SearchParameters to limit the scope of which users are returned.

You can call this method before calling the Portal.ArcGISPortal.InitializeAsync Method and obtain Portal.ArcGISPortalUser information BUT the Portal.ArcGISPortalUser.ArcGISPortal Property will not be populated with valid information (i.e. its value will be Nothing/null). It is a recommended best practice to call the Portal.ArcGISPortal.InitializeAsync Method before calling the Portal.ArcGISPortal.SearchUsersAsync Method so that all of the properties in the Portal.ArcGISPortal.ArcGISPortalUser will contain valid data.

You do not have to be a logged in user using the IdentityManager to get information from the Portal.ArcGISPortal.SearchUsersAsync Method. You can gain this information from anonymous access. However, to obtain information about users in your organization that have a Portal.PortalAccess level of Private you need to use the IdentityManager by supplying the appropriate username/password credentials. As AGOL and ArcGIS Portal require the use of long term tokens to access secured information (i.e. information that is Private) you should remember to set the IdentityManager.TokenGenerationReferer Property to the correct string required by your development platform.

NOTE: While the Portal.ArcGISPortal.SearchUsersAsync Method does return an IEnumberable collection of Portal.ArcGISPortalUser objects as result of the search operation, not all of the Properties of the Portal.ArcGISPortalUser objects will contain data. This is by design to protect certain confidential information about a user. As of AGOL/ArcGIS Portal version 2.1 only the following ArcGISPortalUser Properties will be populated with information for the user search operation: .Username, .FullName, .Description, .Tags. .Culture, .Region, .ThumbnailUri, .CreationDate, and .ModificationDate. For more details on the types of information that can be obtained from the user search operation, review the ArcGIS Portal API REST documentation for the user search operation.

Parameters

searchParameters
The search 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, credentials via username/password if wanting to access secured services, and at least one keyword to search for ArcGIS Portal Users. Once the user information is provided, click the button to make Asynchronous calls to the AGOL/ArcGIS Portal server to retrieve information for display back.

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.

Accessing ArcGISPortal.ArcGISPortalUser information.

XAMLCopy Code
<Grid x:Name="LayoutRoot" Background="White">
  
  <!-- Information the user needs to supply. -->
  
  <!-- 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 Anonymous access or IdentityManager with user credentials to access the information about ArcGISPortalUsers. -->
  <CheckBox Content="Use Anynomous Access" Height="16" Margin="12,113,0,0" Name="CheckBox_UseAnonymousAccess" 
             VerticalAlignment="Top" HorizontalAlignment="Left" Width="165" Click="CheckBox_UseAnonymousAccess_Click" />
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="222,113,0,0" Name="Label_UserName" VerticalAlignment="Top" Width="70" 
                Content="UserName:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="287,109,0,0" Name="TextBox_UserName" VerticalAlignment="Top" Width="210" />
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="506,110,0,0" Name="Label_Password" VerticalAlignment="Top" Width="56" 
              Content="Password:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="565,109,0,0" Name="TextBox_Password" VerticalAlignment="Top" Width="210" />
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,144,0,0" Name="Label_SearchKeywords" VerticalAlignment="Top" 
              Width="231" Content="Search for Users using the keyword(s):"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="239,140,0,0" Name="TextBox_SearchKeywords" VerticalAlignment="Top" 
            Width="536" />
  
  <!-- Button to invoke searching for Users on ArcGIS Online/ArcGIS Portal-->
  <Button Content="Get ArcGIS Portal Users Information" Height="23" HorizontalAlignment="Left" Margin="12,172,0,0" 
           Name="Button1" VerticalAlignment="Top" Width="763" Click="Button1_Click" />
  
  <!-- Display the results to the user. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,203,0,0" Name="Label_GenericInfo" VerticalAlignment="Top" Width="202" 
             Content="Generic ArcGIS Portal Information:"/>
  <TextBlock Height="362" HorizontalAlignment="Left" Margin="12,226,0,0" Name="TextBlock_GenericInfo" Text="TextBlock_GenericInfo" 
             VerticalAlignment="Top" Width="314" />
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="331,203,0,0" Name="Label_UserInfo" VerticalAlignment="Top" Width="194" 
             Content="ArcGIS Portal User Information:"/>
  <ListBox Height="362" HorizontalAlignment="Left" Margin="331,226,0,0" Name="ListBox_UserInfo" 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, credentials via username/password if wanting to access secured services, 
   and at least one keyword to search for ArcGIS Portal Users. Once the user information is provided, click the button to make 
   Asynchronous calls to the AGOL/ArcGIS Portal server to retrieve information for display back." />
  
</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";
  
  // If gaining access to secured services on AGOL/Portal provide Username/Password information.
  TextBox_UserName.Text = "YourUserName";
  TextBox_Password.Text = "YourPassword";
  
  // Provide default keyword(s) to search for ArcGISPortalUsers in AGOL/Portal.
  TextBox_SearchKeywords.Text = "don";
}
            
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 (including user information if trying to access a secured service). Additionally, information
  // about ArcGISPortalUsers is returned based upon a keyword(s) search. 
  
  // Clear out any existing results before proceeding.
  TextBlock_GenericInfo.Text = "";
  ListBox_UserInfo.Items.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();
    
    // Determine if we are going to really use the IdentityManager result to get information from AGOL/Portal.
    if (CheckBox_UseAnonymousAccess.IsChecked == false)
    {
      // The user wants to use their username/password to access secured AGOL/Portal services. Using this option will
      // display Private Users to which the logged in user belongs or is the administrator of.
      
      // 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;
    }
    else
    {
      // The user wants to access publically available information from AGOL/Portal services. Private Users will not
      // be displayed using this option.
      // The need to use the ArcGISPortal.Token is NOT necessary.
    }
    
    // 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.
    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. If we have a valid CurrentUser get that information. If the user tries to get information using
    // anonymous access the default string values of "[NOT AVAILABLE]" are provided.
    ESRI.ArcGIS.Client.Portal.ArcGISPortalUser myCurrentUser = myArcGISPortal.CurrentUser;
    string myUserName = "[NOT AVAILABLE]";
    string myEmail = "[NOT AVAILABLE]";
    if (myCurrentUser != null)
    {
      myUserName = myCurrentUser.UserName;
      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: " + myPortalHostName + Environment.NewLine);
    myStringBuilder.Append("ArcGISPortal.CurrentVersion: " + myCurrentVersion + Environment.NewLine);
    myStringBuilder.Append("ArcGISPortal.Url: " + myUrl + Environment.NewLine);
    myStringBuilder.Append("CurrentUser.UserName: " + myUserName + Environment.NewLine);
    myStringBuilder.Append("CurrentUser.Email: " + myEmail + Environment.NewLine);
    
    // Display the information about the AGOL/Portal server to the user.
    TextBlock_GenericInfo.Text = myStringBuilder.ToString();
    
    //----------------------------------------------------------------
    // Now that the ArcGISPortal.InitializeAsync has successfully been invoked, we can now get more detailed information
    // about ArcGISPortalUser's. 
    
    //  Create a new SearchParameters object.
    ESRI.ArcGIS.Client.Portal.SearchParameters mySearchParameters = new ESRI.ArcGIS.Client.Portal.SearchParameters();
    
    // Get the search keyword(s) for finding Users in the AGOL/Portal server.
    mySearchParameters.QueryString = TextBox_SearchKeywords.Text;
    
    // Allow lots of Users to be returned.
    mySearchParameters.Limit = 1000;
    
    // Use the ArcGISPortal object to access User information in AGOL/Portal services. This will cause an asynchronous call to the 
    // sub-routine called CALLBACK_ArcGISPortal_SearchUsersAsync. 
    myArcGISPortal.SearchUsersAsync(mySearchParameters, CALLBACK_ArcGISPortal_SearchUsersAsync);
  }
  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_ArcGISPortal_SearchUsersAsync(ESRI.ArcGIS.Client.Portal.SearchResultInfo<ESRI.ArcGIS.Client.Portal.ArcGISPortalUser> sri, 
  System.Exception ex)
{
  // This sub-routine executes as a result of the ArcGISPortal.SearchUsersAsync Method.
  
  // Create a StringBuilder class to hold User information obtained from the AGOL/Portal service. Display the 
  // number of Users found in the ListBox.
  System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder();
  myStringBuilder.Append("Number of ArcGIS Portal Users: " + sri.TotalCount.ToString() + Environment.NewLine);
  ListBox_UserInfo.Items.Add(myStringBuilder.ToString());
  
  // Get the results (an IEnumerable of ArcGISPortalUser objects) from the SearchResultInfo object.
  IEnumerable<ESRI.ArcGIS.Client.Portal.ArcGISPortalUser> myResults = sri.Results;
  
  // Loop through each ArcGISPortalUser object.
  foreach (ESRI.ArcGIS.Client.Portal.ArcGISPortalUser myArcGISPortalUser in myResults)
  {
    // Get various ArcGISPortalUser Property information. Like: the image for the user, the username logon of the user, 
    // the provided full name of the user, a description that the user provides about themselves, the date the user created 
    // their account, and the date the user account was last modified.
    Uri myThumbnailUri = myArcGISPortalUser.ThumbnailUri;
    string myUserName = myArcGISPortalUser.UserName;
    string myFullName = myArcGISPortalUser.FullName;
    string myDescription = myArcGISPortalUser.Description;
    DateTime myCreationDate = myArcGISPortalUser.CreationDate;
    DateTime myModificationDate = myArcGISPortalUser.ModificationDate;
    
    // Create a new StackPanel to house the information that will be displayed to the user about each User found.
    StackPanel myStackPanel = new StackPanel();
    myStackPanel.Orientation = Orientation.Vertical;
    
    if (myThumbnailUri != null)
    {
      // If the User has an image, display it.
      
      // Create a new Image object, define its size and set the Uri of the Image to that for the User. 
      Image myImage = new Image();
      myImage.Width = 50;
      myImage.Height = 50;
      myImage.Source = new System.Windows.Media.Imaging.BitmapImage(myThumbnailUri); // Silverlight has issues with .gif format images!
      
      // Display the image on the left in the ListBox.
      StackPanel myStackPanel2 = new StackPanel();
      myStackPanel2.Orientation = Orientation.Horizontal;
      myStackPanel2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
      myStackPanel2.Children.Add(myImage);
      myStackPanel.Children.Add(myStackPanel2);
    }
    else
    {
      // The User does not have an image logo defined. 
      
      // Inform the application user that no user image is available for display. 
      TextBlock myTextBlock_ArcGISPortalUser_ThumbnailImage = new TextBlock();
      myTextBlock_ArcGISPortalUser_ThumbnailImage.Text = "[NO THUMBNAIL IMAGE AVAILABLE]";
      myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_ThumbnailImage);
    }
    
    // Display the logon username of the user.
    TextBlock myTextBlock_ArcGISPortalUser_UserName = new TextBlock();
    myTextBlock_ArcGISPortalUser_UserName.Text = "ArcGISPortalUser.UserName: " + myUserName;
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_UserName);
    
    // Display the provided full name of the user.
    TextBlock myTextBlock_ArcGISPortalUser_FullName = new TextBlock();
    myTextBlock_ArcGISPortalUser_FullName.Text = "ArcGISPortalUser.FullName: " + myFullName;
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_FullName);
    
    // Display the description that user provides about themselves.
    TextBlock myTextBlock_ArcGISPortalUser_Description = new TextBlock();
    myTextBlock_ArcGISPortalUser_Description.Text = "ArcGISPortalUser.Description: " + myDescription;
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_Description);
    
    // Display the creation date of the user logon.
    TextBlock myTextBlock_ArcGISPortalUser_CreationDate = new TextBlock();
    myTextBlock_ArcGISPortalUser_CreationDate.Text = "ArcGISPortalUser.CreationDate: " + myCreationDate.ToString();
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_CreationDate);
    
    // Display the last modification date of the user account.
    TextBlock myTextBlock_ArcGISPortalUser_ModificationDate = new TextBlock();
    myTextBlock_ArcGISPortalUser_ModificationDate.Text = "ArcGISPortalUser.ModificationDate: " + myModificationDate.ToString();
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_ModificationDate);
    
    // Add the various display objects about the User in the ListBox.
    ListBox_UserInfo.Items.Add(myStackPanel);
  }
}
            
private void CheckBox_UseAnonymousAccess_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // This sub-routine execute when the user checks on/off the ability to get information about AGOL/Portal 
  // using anonymous access or via the IdentityManager with a username/password for secured web services.
  
  if (CheckBox_UseAnonymousAccess.IsChecked == true)
  {
    // The user wants to have anonymous access to get AGOL/Portal information.
    // Hide the username/password controls.
    
    Label_Password.Visibility = System.Windows.Visibility.Collapsed;
    Label_UserName.Visibility = System.Windows.Visibility.Collapsed;
    TextBox_Password.Visibility = System.Windows.Visibility.Collapsed;
    TextBox_UserName.Visibility = System.Windows.Visibility.Collapsed;
  }
  else
  {
    // The user wants to have IdentityManager with a username/password access to get AGOL/Portal information.
    // Show the username/password controls.
    
    Label_Password.Visibility = System.Windows.Visibility.Visible;
    Label_UserName.Visibility = System.Windows.Visibility.Visible;
    TextBox_Password.Visibility = System.Windows.Visibility.Visible;
    TextBox_UserName.Visibility = System.Windows.Visibility.Visible;
  }
}
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"
  
  ' If gaining access to secured services on AGOL/Portal provide Username/Password information.
  TextBox_UserName.Text = "YourUserName"
  TextBox_Password.Text = "YourPassword"
  
  ' Provide default keyword(s) to search for ArcGISPortalUsers in AGOL/Portal.
  TextBox_SearchKeywords.Text = "don"
  
End Sub
            
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 (including user information if trying to access a secured service). Additionally, information
  ' about ArcGISPortalUsers is returned based upon a keyword(s) search. 
  
  ' Clear out any existing results before proceeding.
  TextBlock_GenericInfo.Text = ""
  ListBox_UserInfo.Items.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
    
    ' Determine if we are going to really use the IdentityManager result to get information from AGOL/Portal.
    If CheckBox_UseAnonymousAccess.IsChecked = False Then
      
      ' The user wants to use their username/password to access secured AGOL/Portal services. Using this option will
      ' display Private Users to which the logged in user belongs or is the administrator of.
      
      ' 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
      
    Else
      
      ' The user wants to access publically available information from AGOL/Portal services. Private Users will not
      ' be displayed using this option.
      ' The need to use the ArcGISPortal.Token is NOT necessary.
      
    End If
    
    ' 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.
    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. If we have a valid CurrentUser get that information. If the user tries to get information using
    ' anonymous access the default string values of "[NOT AVAILABLE]" are provided.
    Dim myCurrentUser As ESRI.ArcGIS.Client.Portal.ArcGISPortalUser = myArcGISPortal.CurrentUser
    Dim myUserName As String = "[NOT AVAILABLE]"
    Dim myEmail As String = "[NOT AVAILABLE]"
    If myCurrentUser IsNot Nothing Then
      myUserName = myCurrentUser.UserName
      myEmail = myCurrentUser.Email
    End If
    
    ' 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: " + myPortalHostName + vbCrLf)
    myStringBuilder.Append("ArcGISPortal.CurrentVersion: " + myCurrentVersion + vbCrLf)
    myStringBuilder.Append("ArcGISPortal.Url: " + myUrl + vbCrLf)
    myStringBuilder.Append("CurrentUser.UserName: " + myUserName + vbCrLf)
    myStringBuilder.Append("CurrentUser.Email: " + myEmail + vbCrLf)
    
    ' Display the information about the AGOL/Portal server to the user.
    TextBlock_GenericInfo.Text = myStringBuilder.ToString
    
    '----------------------------------------------------------------
    ' Now that the ArcGISPortal.InitializeAsync has successfully been invoked, we can now get more detailed information
    ' about ArcGISPortalUser's. 
    
    '  Create a new SearchParameters object.
    Dim mySearchParameters As ESRI.ArcGIS.Client.Portal.SearchParameters = New ESRI.ArcGIS.Client.Portal.SearchParameters
    
    ' Get the search keyword(s) for finding Users in the AGOL/Portal server.
    mySearchParameters.QueryString = TextBox_SearchKeywords.Text
    
    ' Allow lots of Users to be returned.
    mySearchParameters.Limit = 1000
    
    ' Use the ArcGISPortal object to access User information in AGOL/Portal services. This will cause an asynchronous call to the 
    ' sub-routine called CALLBACK_ArcGISPortal_SearchUsersAsync. 
    myArcGISPortal.SearchUsersAsync(mySearchParameters, AddressOf CALLBACK_ArcGISPortal_SearchUsersAsync)
    
  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_ArcGISPortal_SearchUsersAsync(sri As ESRI.ArcGIS.Client.Portal.SearchResultInfo(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalUser), ex As System.Exception)
  
  ' This sub-routine executes as a result of the ArcGISPortal.SearchUsersAsync Method.
  
  ' Create a StringBuilder class to hold User information obtained from the AGOL/Portal service. Display the 
  ' number of Users found in the ListBox.
  Dim myStringBuilder As New Text.StringBuilder
  myStringBuilder.Append("Number of ArcGIS Portal Users: " + sri.TotalCount.ToString + vbCrLf)
  ListBox_UserInfo.Items.Add(myStringBuilder.ToString)
  
  ' Get the results (an IEnumerable of ArcGISPortalUser objects) from the SearchResultInfo object.
  Dim myResults As IEnumerable(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalUser) = sri.Results
  
  ' Loop through each ArcGISPortalUser object.
  For Each myArcGISPortalUser As ESRI.ArcGIS.Client.Portal.ArcGISPortalUser In myResults
    
    ' Get various ArcGISPortalUser Property information. Like: the image for the user, the username logon of the user, 
    ' the provided full name of the user, a description that the user provides about themselves, the date the user created 
    ' their account, and the date the user account was last modified.
    Dim myThumbnailUri As Uri = myArcGISPortalUser.ThumbnailUri
    Dim myUserName As String = myArcGISPortalUser.UserName
    Dim myFullName As String = myArcGISPortalUser.FullName
    Dim myDescription As String = myArcGISPortalUser.Description
    Dim myCreationDate As Date = myArcGISPortalUser.CreationDate
    Dim myModificationDate As Date = myArcGISPortalUser.ModificationDate
    
    ' Create a new StackPanel to house the information that will be displayed to the user about each User found.
    Dim myStackPanel As New StackPanel
    myStackPanel.Orientation = Orientation.Vertical
    
    If myThumbnailUri IsNot Nothing Then
      
      ' If the User has an image, display it.
      
      ' Create a new Image object, define its size and set the Uri of the Image to that for the User. 
      Dim myImage As New Image
      myImage.Width = 50
      myImage.Height = 50
      myImage.Source = New Imaging.BitmapImage(myThumbnailUri) ' Silverlight has issues with .gif format images!
      
      ' Display the image on the left in the ListBox.
      Dim myStackPanel2 As New StackPanel
      myStackPanel2.Orientation = Orientation.Horizontal
      myStackPanel2.HorizontalAlignment = Windows.HorizontalAlignment.Left
      myStackPanel2.Children.Add(myImage)
      myStackPanel.Children.Add(myStackPanel2)
      
    Else
      
      ' The User does not have an image logo defined. 
      
      ' Inform the application user that no user image is available for display. 
      Dim myTextBlock_ArcGISPortalUser_ThumbnailImage As New TextBlock
      myTextBlock_ArcGISPortalUser_ThumbnailImage.Text = "[NO THUMBNAIL IMAGE AVAILABLE]"
      myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_ThumbnailImage)
      
    End If
    
    ' Display the logon username of the user.
    Dim myTextBlock_ArcGISPortalUser_UserName As New TextBlock
    myTextBlock_ArcGISPortalUser_UserName.Text = "ArcGISPortalUser.UserName: " + myUserName
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_UserName)
    
    ' Display the provided full name of the user.
    Dim myTextBlock_ArcGISPortalUser_FullName As New TextBlock
    myTextBlock_ArcGISPortalUser_FullName.Text = "ArcGISPortalUser.FullName: " + myFullName
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_FullName)
    
    ' Display the description that user provides about themselves.
    Dim myTextBlock_ArcGISPortalUser_Description As New TextBlock
    myTextBlock_ArcGISPortalUser_Description.Text = "ArcGISPortalUser.Description: " + myDescription
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_Description)
    
    ' Display the creation date of the user logon.
    Dim myTextBlock_ArcGISPortalUser_CreationDate As New TextBlock
    myTextBlock_ArcGISPortalUser_CreationDate.Text = "ArcGISPortalUser.CreationDate: " + myCreationDate.ToString
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_CreationDate)
    
    ' Display the last modification date of the user account.
    Dim myTextBlock_ArcGISPortalUser_ModificationDate As New TextBlock
    myTextBlock_ArcGISPortalUser_ModificationDate.Text = "ArcGISPortalUser.ModificationDate: " + myModificationDate.ToString
    myStackPanel.Children.Add(myTextBlock_ArcGISPortalUser_ModificationDate)
    
    ' Add the various display objects about the User in the ListBox.
    ListBox_UserInfo.Items.Add(myStackPanel)
    
  Next
  
End Sub
            
Private Sub CheckBox_UseAnonymousAccess_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' This sub-routine execute when the user checks on/off the ability to get information about AGOL/Portal 
  ' using anonymous access or via the IdentityManager with a username/password for secured web services.
  
  If CheckBox_UseAnonymousAccess.IsChecked = True Then
    
    ' The user wants to have anonymous access to get AGOL/Portal information.
    ' Hide the username/password controls.
    
    Label_Password.Visibility = Windows.Visibility.Collapsed
    Label_UserName.Visibility = Windows.Visibility.Collapsed
    TextBox_Password.Visibility = Windows.Visibility.Collapsed
    TextBox_UserName.Visibility = Windows.Visibility.Collapsed
    
  Else
    
    ' The user wants to have IdentityManager with a username/password access to get AGOL/Portal information.
    ' Show the username/password controls.
    
    Label_Password.Visibility = Windows.Visibility.Visible
    Label_UserName.Visibility = Windows.Visibility.Visible
    TextBox_Password.Visibility = Windows.Visibility.Visible
    TextBox_UserName.Visibility = Windows.Visibility.Visible
    
  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.