AnsweredAssumed Answered

Release selected file from onCmd to modify it?

Question asked by Jonathan Prill on Jan 3, 2019

Is it possible to so-called release a file so that it can be modified in a later part of an add-in?


For context: I am writing an add-in that replaces a PDF that is currently in our vault with one that is on my desktop while maintaining the metadata from the original PDF. When I call the add-in and (after I get the metadata I want) try to delete the document using File.Delete(src) it (as expected) returns that the document is in use, which I am assuming it is in use by PDM.


I am wondering:

Is it possible to right click on a pdf, get the file ID and other relevant information and then release the object so that I can delete the file all within the same add-in?


FYI - I am new to programming and this is my first PDM Add-in.


For reference here is a bit of my onCmd sub in my add-in:


If poCmd.meCmdType = EdmCmdType.EdmCmd_Menu Then

            If poCmd.mlCmdID = 1000 Then

                If ppoData(index).mlObjectID1 = 0 Then

                    MessageBox.Show("Invalid selection. Please select a PDF and try again.")

                    Exit Sub



                    'Get to-be-replaced (right-clicked) file information using PDM API


                    Dim myVault As IEdmVault19

                    Dim myFile As IEdmFile13

                    Dim myFileID As Integer

                    Dim poFolderID As Integer

                    Dim parentID As Integer


                    myVault = poCmd.mpoVault

                    myFile = myVault.GetObject(EdmObjectType.EdmObject_File, ppoData(0).mlObjectID1)

                    myFileID = myFile.ID

                    poFolderID = poCmd.mlCurrentFolderID

                    parentID = ppoData(0).mlObjectID3


                    Dim toBeReplaced_pth As String

                    toBeReplaced_pth = myFile.GetLocalPath(parentID)


                    'Check to see if file is checked out - if it is not, check it out

                    If Not myFile.IsLocked Then

                        myFile.LockFile(poFolderID, 0)

                    End If




                    File.Replace(src, toBeReplaced, Nothing)


                    'Check it back in, voila!