List out Files from the Directory using Session Objects in VB API

List out Files from the Directory using Session Objects in VB API

Creo Parametric VB API allows the user to get the list of files available in the directory. Let’s check how it is working with the sample code.

Steps to follow

  1. Create a IpfcAsyncConnection
  2. Create a IpfcBaseSession
  3. Retrieve the session from IpfcAsyncConnection
  4. Get the files by passing the arguments File Version, If any custom version, and File Path
  5. Add the file name to the list for reference

Sample Code:

Public AConnection As IpfcAsyncConnection
Public BSession As IpfcBaseSession

Private Sub btn_list_session_files(sender As Object, e As RoutedEventArgs) Handles btn_list_session_files.Click
        BSession = AConnection.Session

        ' Textbox in the UI to retrieve custom file version
        Dim Filter As String = tb_CustomVersion.Text

        Dim Version As EpfcFileListOpt

        ' Checkbox in the UI to allow the user to retrieve only latest version or all the version
        If rb_LatestVersion.IsChecked Then
            Version = EpfcFileListOpt.EpfcFILE_LIST_LATEST
            Version = EpfcFileListOpt.EpfcFILE_LIST_ALL
        End If

        ' File Path
        Dim Path = tb_ListFilePath.Text

        'Iterate every files in the Base Session
        For Each items In BSession.ListFiles(Filter, Version, Path)

    Catch ex As Exception
        MessageBox.Show(ex.ToString, "Error Message")
    End Try
End Sub

Leave a Reply

Contact Us