Select to view content in your preferred language

iterate through rows of feature service

233
2
Jump to solution
06-26-2024 07:59 PM
AntDevEsk
Occasional Contributor

how do i iterate through the rows of a feature service form portal?

i have a list of portal items as per this url

CreateForItemsOfType Method—ArcGIS Pro

i can iterate through and get the item name etc but how do i do the equivalent of a python searchCursor? 

i just want to find a value in a field.

i have searched for hours, what am i missing?

0 Kudos
1 Solution

Accepted Solutions
AntDevEsk
Occasional Contributor

solved 

need to have the table name with the layer index of the table as a prefix, in my case it is Layer 1 so its prefixed with "L0", i.e 

using (Table table = geodatabase.OpenDataset<Table>($"L0{pi.Name}"))

 

View solution in original post

0 Kudos
2 Replies
AntDevEsk
Occasional Contributor

I have made some progress, now the issue is it throws the error that the table cant be found, yet i get the name from the item, i cant believe this is so difficult

foreach (var pi in portalItems)
{
    if (pi.Name == <TABLE_NAME>)
    {
        MessageBox.Show($"ITEM : {pi}");
        MessageBox.Show($"ITEM NAME : {pi.Name}");
        MessageBox.Show($"ITEM NAME : {pi.Path}");                  
      

        Uri uri = new Uri(pi.Path);
        ServiceConnectionProperties serviceConnectionProperties = new ServiceConnectionProperties(uri);
        using (Geodatabase geodatabase = new Geodatabase(serviceConnectionProperties))
        {
            using (Table table = geodatabase.OpenDataset<Table>(pi.Name))
            {                
                
                using (RowCursor rowCursor = table.Search(null,false))
                {
                    while (rowCursor.MoveNext())
                    {
                        using (Row row = rowCursor.Current)
                        {
                            string val = Convert.ToString(row["NAME"]);
                            MessageBox.Show(val);
                        }
                    }
                }

            }
        }
    }
}

 

0 Kudos
AntDevEsk
Occasional Contributor

solved 

need to have the table name with the layer index of the table as a prefix, in my case it is Layer 1 so its prefixed with "L0", i.e 

using (Table table = geodatabase.OpenDataset<Table>($"L0{pi.Name}"))

 

0 Kudos