Vault 2014 API example getting property values of a file

By Wayne Brill

This VB example uses GetPropertyDefinitions() and the GetPropertyValue() of the the PropertyManager to retrieve the value of system and a user defined property (UDP) for a file. It may not be  obvious how to get the PropertyDefinition parameter that you need to pass to GetPropertyValue().

To get the PropertyDefinition you can use GetPropertyDefinitions() which returns a PropertyDefinitionDictionary which is a key value pair. The value of the KeyValuePair are property definitions. In this example the display name of the PropertyDefinition is used to find a user defined property to use with GetPropertyValue().

For system properties you can use one of the members of PropertyDefinitionIds.Server. This example is using PropertyDefinitionIds.Server.LifeCycleDefinition and PropertyDefinitionIds.Server.VersionNumber.

To try this code you can add a button to the VaultList SDK sample and copy in this code.

Private Sub Button5_Click(sender As System.Object, _            e As System.EventArgs) Handles Button5.Click             ' For demonstration purposes,         'the information is hard-coded.        Dim results As VDF.Vault.Results.LogInResult =            VDF.Vault.Library.ConnectionManager.LogIn _          ("localhost", "Vault", "Administrator", "", _                      VDF.Vault.Currency.Connections. _                 AuthenticationFlags.Standard, Nothing)             If Not results.Success Then            Return        End If             Dim m_conn As  _            VDF.Vault.Currency.Connections.Connection _                                   = results.Connection             Dim props As PropertyDefinitionDictionary = _         m_conn.PropertyManager.GetPropertyDefinitions(       VDF.Vault.Currency.Entities.EntityClassIds.Files,           Nothing, PropertyDefinitionFilter.IncludeAll)             Dim myKeyValPair As KeyValuePair _                         (Of String, PropertyDefinition)        Dim myUDP_DayOFSave As PropertyDefinition _                                               = Nothing             Dim propDef As PropertyDefinition        For Each myKeyValPair In props            ' Property definition from KeyValuePair            propDef = myKeyValPair.Value()            ' Using the display name to identify             ' the PropertyDefinition            If propDef.DisplayName = _                             "wb_Day_Of_IDW_Save" Then                'It is the PropertyDefinition                 myUDP_DayOFSave = propDef                Exit For            End If        Next             Dim myLifeCycleDef As PropertyDefinition = _        props(PropertyDefinitionIds.Server. _             &#1
60;                  LifeCycleDefinition)             Dim myVerNumDef As PropertyDefinition = _        props(PropertyDefinitionIds.Server. _                                      VersionNumber)             ' Get the FileIteration         Dim fileIter As  _    VDF.Vault.Currency.Entities.FileIteration = Nothing             'Change this to the name of a file in your vault        fileIter = _    getFileIteration("wB_Assembly_9-23-13.idw", m_conn)             'Name of the life cycle definition        Dim strLifeCycleName As String = _            m_conn.PropertyManager.GetPropertyValue _                      (fileIter, myLifeCycleDef, Nothing)             'Version number        Dim strVersionNumber As String = _            m_conn.PropertyManager.GetPropertyValue _                        (fileIter, myVerNumDef, Nothing)             'Get the user defined property value        If Not myUDP_DayOFSave Is Nothing Then            Dim strPropertyVal As String = _                m_conn.PropertyManager.GetPropertyValue _                     (fileIter, myUDP_DayOFSave, Nothing)                 MessageBox.Show("Value of custom prop " _                & myUDP_DayOFSave.DisplayName.ToString() _                & " = " & strPropertyVal)        End If         End Sub

Here is the code that gets the FileIteration.

Public Function getFileIteration _              (nameOfFile As String, _                      connection As  _                 VDF.Vault.Currency. _             Connections.Connection) _              As VDF.Vault.Currency. _               Entities.FileIteration             Dim conditions As ACW.SrchCond()             ReDim conditions(0)             Dim lCode As Long = 1             Dim Defs As ACW.PropDef() = _      connection.WebServiceManager. _                   PropertyService. _    GetPropertyDefinitionsByEntityClassId("FILE")             Dim Prop As ACW.PropDef = Nothing             For Each def As ACW.PropDef In Defs            If def.DispName = _                      "File Name" Then                Prop = def            End If        Next def             Dim searchCondition As  _    ACW.SrchCond = New ACW.SrchCond()             searchCondition.PropDefId = _                              Prop.Id             searchCondition.PropTyp = _    ACW.PropertySearchType.SingleProperty        searchCondition.SrchOper = lCode             searchCondition.SrchTxt = nameOfFile             conditions(0) = searchCondition             ' search for files        Dim FileList As List _    (Of Autodesk.Connectivity.WebServices.File) = _        New List _    (Of Autodesk.Connectivity.WebServices.File) '()        Dim sBookmark As String = String.Empty        Dim Status As ACW.SrchStatus = Nothing             While (Status Is Nothing OrElse _             FileList.Count < Status.TotalHits)                 Dim files As Autodesk.Connectivity. _    WebServices.File() = connection.WebServiceManager.    DocumentService.FindFilesBySearchConditions _                                 (conditions, _                Nothing, Nothing, True, True, _                             sBookmark, Status)                 If (Not files Is Nothing) Then                FileList.AddRange(files)            End If        End While             Dim oFileIteration As  _            VDF.Vault.Currency.Entities. _                   FileIteration = Nothing        For i As Integer = _                  0 To FileList.Count - 1            If FileList(i).Name = _                          nameOfFile Then                oFileIteration = _               New VDF.Vault.Currency. _    Entities.FileIteration(connection, _                            FileList(i))            End If        Next             Return oFileIteration         End Function

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading