1: Public Shared Function GetSelectedKeysString(ByRef siteConn As MgSiteConnection, _
2: ByRef resSvc As MgResourceService, ByVal oMap As MgMap, ByVal SessionId As String, _
3: ByVal SelectionXML As String, ByVal layerResID As MgResourceIdentifier, _
4: ByVal keyFieldName As String) As String
5:
6: Dim szKeys As String = ""
7: Dim oSel As New MgSelection(oMap)
8: oSel.FromXml(SelectionXML)
9: Dim curLay As MgLayerBase
10: 'isolate the layer
11: For Each layerItem As MgLayerBase In oSel.GetLayers
12: If layerItem.Name = layerResID.Name Then
13: curLay = layerItem
14: End If
15: Next
16:
17: Dim featSvc As MgFeatureService = siteConn.CreateService(MgServiceType.FeatureService)
18: Dim queryOptions As New MgFeatureQueryOptions
19: Dim featureClassName As String = curLay.GetFeatureClassName
20: 'workaround using GenerateFilters and looping through the results as needed
21: Dim featureReader As MgFeatureReader
22: Dim filters As MgStringCollection = oSel.GenerateFilters(curLay, featureClassName, 20)
23: Dim filterCnt As Integer = 0
24: While filterCnt < filters.GetCount
25: queryOptions.SetFilter(filters.GetItem(filterCnt))
26: featureReader = featSvc.SelectFeatures(New MgResourceIdentifier(curLay.GetFeatureSourceId), featureClassName, queryOptions)
27: While featureReader.ReadNext
28: If szKeys = "" Then
29: szKeys = ConvertPropertyToString(featureReader, keyFieldName)
30: Else
31: szKeys &= "," & ConvertPropertyToString(featureReader, keyFieldName)
32: End If
33: End While
34: featureReader.Close()
35: featureReader.Dispose()
36: filterCnt += 1
37: End While
38: Return szKeys
39: End Function