ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Core Namespace / ArcGISPortalExtensions Class / GetUserContentAsync Method
the username
optional folderid
Example

In This Topic
    GetUserContentAsync Method
    In This Topic
    Gets the given username's content. Items are either in the home folder for the user, e.g. /content/users/{username} or in a subfolder of the home folder with the given folder ID. Multilevel folders are not supported.
    Syntax
    public static Task<PortalUserContent> GetUserContentAsync( 
       ArcGISPortal portal,
       string username,
       string folderId
    )
    Public Shared Function GetUserContentAsync( _
       ByVal portal As ArcGISPortal, _
       ByVal username As String, _
       Optional ByVal folderId As String _
    ) As Task(Of PortalUserContent)

    Parameters

    portal
    username
    the username
    folderId
    optional folderid

    Return Value

    Exceptions
    ExceptionDescription
    Thrown when an invalid portal is provided as the active portal.
    username cannot be null or empty.
    You must be signed on to get user content.
    You do not have permissions to access this resource or perform this operation.
    Request failed: status code {status code}.
    Remarks
    Executes the following portal rest query:
    {portalURL}sharing/rest/content/users/{userName}

    or {portalURL}sharing/rest/content/users/{userName}/{folderId} if a folderid was provided. Users executing this query must be signed on or an exception will be thrown.
    Example
    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: Download any package items in the user content
    //user content previously from...
    //var userContent = await portal.GetUserContentAsync(owner);
    
    var packages = new List<PortalItemType>
    {
      PortalItemType.BasemapPackage,
      PortalItemType.GeoprocessingPackage,
      PortalItemType.LayerPackage,
      PortalItemType.LocatorPackage,
      PortalItemType.MapPackage,
      PortalItemType.ProjectPackage,
      PortalItemType.ScenePackage,
      PortalItemType.RulePackage,
      PortalItemType.VectorTilePackage
    };
    var folder = @"E:\Temp\PortalAPITest\";
    foreach (var di in userContent.PortalItems.Where(pi => packages.Contains(pi.PortalItemType)))
    {
      var path = System.IO.Path.Combine(folder, di.Name);
      await di.GetItemDataAsync(path);
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also