admin@creocustomization.com

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

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

list out files in the directory using session objects using Creo Parametric 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
    Try
        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
        Else
            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)
            lst_Files.Items.Add(items)
        Next


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

Leave a Reply

Contact Us