ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Core Namespace / ArcGISPortal Class / GetSignOnUsername Method
Example

In This Topic
    GetSignOnUsername Method
    In This Topic
    Gets the username for the current connection This method should be called from within a QueuedTask or System.Threading.Task unless the caller is within ArcGIS.Desktop.Framework.Contracts.ConfigurationManager.OnApplicationInitializing in which case the main thread should be used.
    Syntax
    public string GetSignOnUsername()
    Public Function GetSignOnUsername() As String
    Exceptions
    ExceptionDescription
    Thrown when a method is called on the wrong Pro thread
    Example
    Portal: Get the Current signed in User from the active portal
    var portal = ArcGISPortalManager.Current.GetActivePortal();
    //Force login
    if (!portal.IsSignedOn())
    {
      portal.SignIn();
    }
    var user = portal.GetSignOnUsername();
    
    Portal: Get the user content for the active user from the active portal
    var portal = ArcGISPortalManager.Current.GetActivePortal();
    var owner = portal.GetSignOnUsername();
    var userContent = await portal.GetUserContentAsync(owner);
    //Get content for a specific folder (identified by its folder id)
    //var userContent = await portal.GetUserContentAsync(owner, folderId);
    
    //Get all the folders
    foreach (var pf in userContent.PortalFolders)
    {
      //Do something with the folders
    
    }
    
    //Get all the content items
    foreach (var pi in userContent.PortalItems)
    {
      //Do something with the portal items
    }
    
    Portal: Execute a portal search
    var portal = ArcGISPortalManager.Current.GetPortal(portalUri);
    var owner = portal.GetSignOnUsername();
    var portalInfo = await portal.GetPortalInfoAsync();
    
    //1. Get all web maps
    var query1 = PortalQueryParameters.CreateForItemsOfType(PortalItemType.WebMap);
    
    //2. Get all web maps and map services - include user, organization
    // and "usa" in the title
    var query2 = PortalQueryParameters.CreateForItemsOfTypes(new List<PortalItemType>() {
      PortalItemType.WebMap, PortalItemType.MapService}, owner, "", "title:usa");
    query2.OrganizationId = portalInfo.OrganizationId;
    
    //retrieve in batches of up to a 100 each time
    query2.Limit = 100;
    
    //Loop until done
    var portalItems = new List<PortalItem>();
    while (query2 != null)
    {
      //run the search
      PortalQueryResultSet<PortalItem> results = await portal.SearchForContentAsync(query2);
      portalItems.AddRange(results.Results);
      query2 = results.NextQueryParameters;
    }
    
    //process results
    foreach (var pi in portalItems)
    {
      //Do something with the portal items
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also