9 Replies Latest reply on Dec 18, 2012 3:02 PM by Greg Rupp

    Trouble with CopyFile method

    David Bush

      I am relatively new to programming add-in's for EPDM and need some help tracking down this error. I am writing the API in Visual Basic 2008 Express and my vault version is 2012 sp02.

       

      This add-in is supposed to copy a document from a folder and add the copy one level up. The name of the new file is going to be populated by a serial number, but I am using a placeholder "ECONUMBER" until I can get the CopyFile command to work.

       

      When I run the add-in, the error I am getting is "Object reference not set to an instance of an object." I tracked the error down to the CopyFile command, but cannot get much further. Here is the section of code which I copied almost exactly from the Programmer's Reference Guide. If my issue isn't obvious from this section of the code I can post the whole thing. Thanks for your help!

       

       

                              Dim srcFolder As IEdmFolder5    'source folder variable

                              Dim file As IEdmFile5     'source file variable

                              Dim destFolder As IEdmFolder5    'destination folder variable

                              Dim fileID As String    'variable to store new file ID

       

                              srcFolder = ivault.GetFolderFromPath("C:\VAULT\00 - Engineering Change Orders\Requests")

                              file = ivault.GetFileFromPath("C:\VAULT\00 - Engineering Change Orders\Requests" & iFileName, srcFolder)    'populate source file variable

                              destFolder = ivault.GetFolderFromPath("C:\VAULT\00 - Engineering Change Orders")    'populate destination file variable

       

                              MsgBox("Variables Assigned", MsgBoxStyle.OkOnly) 'for debugging; this MsgBox displays before the error occurs

       

                              fileID = destFolder.CopyFile(file.ID, srcFolder.ID, 0, "ECONUMBER") 'copy file and store ID in fileID variable

       

                              MsgBox("Copy File Was Successful" & vbLf & _

                                    "Source Filename: " & iFileName & vbLf & _

                                   "New File ID: " & fileID & vbLf, MsgBoxStyle.OkOnly)

        • Re: Trouble with CopyFile method
          Greg Rupp

          are "srcfolder" and "file" properly getting set to an object? Does file.id and srcfolder.id return values?

          • Re: Trouble with CopyFile method
            Tim Webb

            Hi David, I have another question.

             

            Based on your code, iFileName doesn't appear to be getting set and your line of code to return the 'srcFolder' variable has a bad input missing a '\' I think.

             

                                    file = ivault.GetFileFromPath("C:\VAULT\00 - Engineering Change Orders\Requests" & iFileName, srcFolder)    'populate source file variable

             

             

            I think the input your are providing is missing the '\'

             

            I believe your code could possibly need to be "...\Requests\" & iFileName rather than "...\Requests" & iFileName

             

            Is iFileName being passed in or set in the OnCmd before the beginning of your code shown?

             

            Thoughts?

            Tim

              • Re: Trouble with CopyFile method
                David Bush

                Tim,

                 

                Thanks for your input. I ended up removing both the "file" and "srcFolder" variables and using the variables I had already set the file and folder objects to. Had I stuck with these ones that missing "\" probably would have driven me mad.

                 

                Once I started using the other set of variables everything starting working like a charm.

              • Re: Trouble with CopyFile method
                David Bush

                So, I've run into another roadblock with this API. I'm sure my problem is obvious, but it's driving me crazy. Any helpful questions or advice would be really appreciated.

                 

                I was able to get the copyfile method working and everything seemed just fine and dandy until I tried running the script as a "commoner" (a la Jeff Sweeny). Before I had been testing the add-in with my admin account, but now that I was using a regular user account I started getting a "You don't have permission to perform this action" error.

                 

                I went back and checked the permissions on the states of the source and destination files and even went as far as giving the "commoner" all permissions on all the states in the source file's workflow and on the destination file state. Still no luck. If I log in as that same "commoner" I can manually copy and paste the file without any problems.

                 

                What really puzzed me was when I set source state to "Ignore Permissions if Previous States" the Admin account started getting the same error. What is going on here? Am I losing my mind?

                  • Re: Trouble with CopyFile method
                    Greg Rupp

                    Remember your folder permissions have to allow for that action as well. Are you just copying a file to a new location or are doing other things as well; such as deleting the old, renaming, setting variable info... etc.?

                      • Re: Trouble with CopyFile method
                        David Bush

                        Greg,

                         

                        Thanks for your help. I forgot to mention that I also checked the folder permission and for both the source and destination file and nothing was missing. Here is the code for what I am doing. I am not deleting the old file, but I am naming the file based on a serial number.

                         

                        If poCmd.meCmdType = EdmCmdType.EdmCmd_Menu Then

                         

                                        'Dimension variables

                                        Dim ivault As IEdmVault5

                                        Dim pvault As IEdmVault7

                                        Dim isrcFile As IEdmFile5

                                        Dim isrcFolder As IEdmFolder5

                                        Dim iDestFolder As IEdmFolder5

                                        Dim iDestFileID As String

                                        Dim pSerNo As IEdmSerNoGen7

                                        Dim ivalue As IEdmSerNoValue

                                       

                                        'set values

                                        ivault = poCmd.mpoVault

                                        pvault = poCmd.mpoVault

                                        isrcFile = ivault.GetFileFromPath("C:\VAULT\15 - Templates\Engineering Change Order\Template - Engineering Change Order Request.doc")

                                        isrcFolder = ivault.GetFolderFromPath("C:\VAULT\15 - Templates\Engineering Change Order")

                                        iDestFolder = ivault.GetFolderFromPath("C:\VAULT\00 - Engineering Change Orders")

                         

                                        'Get Next ECO Number

                                        pSerNo = pvault.CreateUtility(EdmUtility.EdmUtil_SerNoGen)

                                        ivalue = pSerNo.AllocSerNoValue("ECO num")

                         

                                        'copy file and store ID in fileID variable

                                        iDestFileID = iDestFolder.CopyFile(isrcFile.ID, isrcFolder.ID, 0, ivalue.Value & ".doc")

                                     

                                    End If

                          • Re: Trouble with CopyFile method
                            David Bush

                            I went through the folder and state permissions one-by-one again and pin pointed what was missing. I'm not sure why, but it wanted me to have check-out and add-new file permissions on the source folder and state. It's working now, but I still don't understand why it requires those permissions or why "Ignore Permissions if Previous States" locked out the Admin user.

                             

                            Anyway, thanks for your help Greg. This forum has been a huge help to me in learning EPDM API (especially when I get stuck on the stupid stuff).

                              • Re: Trouble with CopyFile method
                                Greg Rupp

                                When you copy a file, you are essentially making a new one. That is why you need the Add new file.

                                When you move a file, it does a copy, add, then delete, so you need to be able to delete on files that move.

                                 

                                I'm still learning myself, but you are correct.. this forum is good resource.