ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Core Namespace / ArcGISPortalExtensions Class / SearchForContentAsync Method
The search parameters.
Example

In This Topic
    SearchForContentAsync Method
    In This Topic
    Searches for portal items from a query string.
    Syntax

    Parameters

    portal
    queryParams
    The search parameters.

    Return Value

    Exceptions
    ExceptionDescription
    Thrown when an invalid portal is provided as the active portal.
    queryParams cannot be null.
    BoundingBox spatial reference must be WGS84.
    You do not have permissions to access this resource or perform this operation.
    Request failed: status code {status code}.
    Remarks

    This method returns a ArcGIS.Desktop.Core.Portal.PortalQueryResultSet<T> object that contains ArcGIS.Desktop.Core.Portal.PortalItem objects. Use the ArcGIS.Desktop.Core.Portal.PortalQueryResultSet<T>.Results property to get the collection of ArcGIS.Desktop.Core.Portal.PortalItem objects.

    You do not have to be a logged in user to search against the specified portal. However, an anonymous user will not be able to get information about items that have a ArcGIS.Desktop.Core.Portal.PortalAccess level of Private

    Comprehensive details on advanced search strings that follow the REST specification can be found in the Search Reference document in the ArcGIS Portal API.

    The following are a few advanced REST search scenarios with example strings that you may consider using for the ArcGIS.Desktop.Core.Portal.PortalQueryParameters.Query Property:

    To find one specific Item by it's Id: "id:00e5e70929e14055ab686df16c842ec1"
    To find all WebMap Items with the word 'florida' in the Title field: "title:florida AND type:web map"
    To find all Layer Package Items with the word 'florida' in the Title field: "title:florida AND type:layer package"
    To find all Items with the word 'florida' in any text field: "florida" (this results in 'q=florida')
    To find all Items with the word 'florida' in the Title field and the word 'esri' in the LicenseInfo field: "title:florida AND licenseinfo:esri"
    To find all Items with the word 'florida' in the Title field and not have the word 'esri' in the LicenseInfo field: "title:florida NOT licenseinfo:esri"
    To find all Items with located within a specific spatial extent and the word 'esri' in the LicenseInfo: "extent:[-114.3458, 21.7518] - [-73.125, 44.0658] AND licenseinfo:esri"
    To find all Items with a SpatialReference.WKID of 4267: "spatialreference:4267"
    To find all Items with a SpatialReference.WKID of 4267 or have the word 'usa' in the Title field: "spatialreference:4267 OR title:usa"

    Example
    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