Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Getting Started

Lesson 2: Search for assets

  • Last UpdatedFeb 19, 2026
  • 2 minute read

After completing this lesson, you will be able to perform the following tasks:

  • Use the AF SDK to search for assets (elements and their attributes).

  • Experiment with different search criteria.

  • Evaluate handling search results.

Before you get started

The following methods and data types are used in this lesson:

Search results and query methods

We recommend performing queries on the server, not on the client application. In other words, you should have the server process search results instead of writing custom search logic in the client code.

Beginning with PI AF 2016 (version 2.8), query methods that process query strings are available instead of methods for each type of search. The exercises in this section use the new AFSearch methods, such as the AFElementSearch class.

Lesson 2 scenario

In this lesson, assume the role of a software developer at a power company. Your assignment is to develop a client application that allows users to search for electric meters (PI AF Elements) and attributes. When the application is complete, users should be able to search for meters by name, element template, element category, and attribute values. Users should also be able to search for meter attributes by name, element template, and attribute category.

Use the PI AF database named Green Power Company, which is located on your PI AF server. You will be asked to write several methods that search for elements and attributes and print the search results to the console. Before starting, it might help to familiarize yourself with the Green Power Company database using PI System Explorer.

Code example

The first example problem and solution are shown here. For this first problem, you should implement the following methods inside Program2.cs and run the application with the arguments provided for each of the following methods in Main().

static void FindMetersByName(AFDatabase database, string elementNameFilter)
{
Console.WriteLine("Find Meters by Name: {0}", elementNameFilter);

// Default search is as an element name string mask.
string querystring = string.Format("{0}", elementNameFilter);
AFElementSearch elementquery = new AFElementSearch(database,
"ElementSearch", querystring);
foreach (AFElement element in elementquery.FindElements())
{
Console.WriteLine("Element: {0}, Template: {1}, Categories: {2}",
element.Name,
element.Template.Name,
element.CategoriesString);
}
Console.WriteLine();

TitleResults for “How to create a CRG?”Also Available in