M-Files API 22.6.11519.0
SearchForObjectsByCondition Method
VaultObjectSearchOperations Object : SearchForObjectsByCondition Method
The search condition to use in the operation.
If this is set to "true", the results are sorted from A to Z based on their display name.
Searches the vault for objects that match the specified condition. Only the latest versions are searched for.
Visual Basic
Public Function SearchForObjectsByCondition( _
   ByVal SearchCondition As SearchCondition, _
   ByVal SortResults As Boolean _
) As ObjectSearchResults
The search condition to use in the operation.
If this is set to "true", the results are sorted from A to Z based on their display name.
Sub SearchForObjectsByClass

    ' Initialize the API and connect to a vault.
    Dim oVault As MFilesAPI.Vault
    ' ...

    ' We are searching for objects from class "Sales Invoice" (ID is 89 in Sample Vault).
    Dim iClass As Integer
    iClass = 89 ' In this case, this identifies the class "Sales Invoice".

    ' You might also want to use the enclosed helper function to resolve the class ID from the class name:
    iClass = MF_FindClassID(oVault, "Sales Invoice")

    ' Create a search condition for the object class.
    Dim oSearchCondition As MFilesAPI.SearchCondition = New MFilesAPI.SearchCondition
    oSearchCondition.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
    oSearchCondition.Expression.DataPropertyValuePropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefClass
    oSearchCondition.TypedValue.SetValue(MFilesAPI.MFDataType.MFDatatypeLookup, iClass)

    ' Invoke the search operation.
    Dim oObjectVersions As MFilesAPI.ObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByCondition( _
            oSearchCondition, False)

    ' Simply process the search results.
    For Each oObjectVersion As MFilesAPI.ObjectVersion In oObjectVersions

        ' Resolve the object type.
        Dim oObjType As MFilesAPI.ObjType
        oObjType = oVault.ObjectTypeOperations.GetObjectType(oObjectVersion.ObjVer.Type)

        ' Output the result.
        Call Console.WriteLine("Title of " + oObjType.NameSingular + ": " + oObjectVersion.Title)


End Sub

' Helper function to find the class ID by a class name.
Function MF_FindClassID( _
            ByRef oVault As MFilesAPI.Vault, _
            ByVal szClassName As String) As Integer

    ' Set the search conditions for the value list item.
    Dim oScValueListItem As New MFilesAPI.SearchCondition
    oScValueListItem.Expression.SetValueListItemExpression( _
        MFilesAPI.MFValueListItemPropertyDef.MFValueListItemPropertyDefName, _
    oScValueListItem.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
    oScValueListItem.TypedValue.SetValue(MFilesAPI.MFDataType.MFDatatypeText, szClassName)
    Dim arrSearchConditions As New MFilesAPI.SearchConditions
    arrSearchConditions.Add(-1, oScValueListItem)

    ' Search for the value list item.
    Dim results As MFilesAPI.ValueListItemSearchResults
    results = oVault.ValueListItemOperations.SearchForValueListItemsEx(MFilesAPI.MFBuiltInValueList.MFBuiltInValueListClasses, arrSearchConditions)
    If results.Count > 0 Then
        ' Found.
        MF_FindClassID = results(1).ID
        ' Not found.
        MF_FindClassID = -1
    End If
End Function

See Also

VaultObjectSearchOperations Object  | VaultObjectSearchOperations Members