1 Reply Latest reply on Oct 13, 2014 1:17 PM by Chris Sonon

    Transfer list of files from epdm

    Rick Rohret

      I am trying to transfer a list of files (pdf and dwg) automatically out of our EPDM vault. The code works on a workstation with  the my EPDM but it will not work on the EPDM viewer that our materials guy uses.  It seems that one of the commands is trying to change a file which he does not have the rights to do and I end up with an incorrect file version error. I only want to copy the file out of the vault.

       

      When I run the code on the EPDM view software I get an incorrect version error that happens at the ver.GetFileCopy location below:

       

                              Dim verEnum As IEdmEnumeratorVersion5
                              verEnum = file
                              Dim Version As Integer
                              Version = file.GetLocalVersionNo(Folder.ID)

                              Dim ver As IEdmVersion5
                              ver = verEnum.GetVersion(Version)
                              ver.GetFileCopy(Me.Handle.ToInt32(), FinsavepathDWG, 0)
                         

       

      See most of the code below:

       

      Imports System.Runtime.InteropServices
      Imports System
      Imports System.IO
      Imports System.Windows.Forms
      Imports System.String
      Imports EdmLib

      Public Class Form1
          Private vault1 As IEdmVault5 = Nothing

          Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
              Dim ReadPathPDF As String
              Dim ReadPathDWG As String
              Dim SavePath As String
              Dim SavePathname As String
              Dim FileRnamePDF As String
              Dim FINsavepathPDF As String
              Dim FinsavepathDWG As String
              Dim TestName As String
              Dim strrdr As New StreamReader("C:\print\XFer.txt")
              Dim srPDF As New StreamWriter("C:\print\pdf\MissingPDF.txt")
              Dim srDWG As New StreamWriter("C:\print\dwg\MissingDWG.txt")

              ReadPathPDF = "C:\Genesis_EPDM\GSG\Build Documents\Build Drawings\PDF\"
              ReadPathDWG = "C:\Genesis_EPDM\GSG\Build Documents\Build Drawings\AUTOCAD\"
              SavePath = "C:\Genesis_EPDM\GSG\Build Documents\MATERIALS\REFERENCE ITEMS\"
              SavePath = "C:\print\"
              SavePathname = "C:\print\XFer.txt"
              FINsavepathPDF = "C:\print\pdf\"
              FinsavepathDWG = "C:\print\dwg\"

              Dim vault As New EdmVault5 'Open vault and get latest number

              vault.LoginAuto("Genesis_EPDM", Me.Handle.ToInt32())

              Dim userMgr As IEdmUserMgr5
              userMgr = vault

              If vault Is Nothing Then
                  vault = New EdmVault5()
              End If

              If Not vault.IsLoggedIn Then
                  vault.LoginAuto("Genesis_EPDM", Me.Handle.ToInt32())
              End If

              TestName = strrdr.ReadLine

              Button1.Hide()
              Show()

              Do While TestName <> "END"

                  Label1.Text = TestName


                  If Strings.Right(TestName, 4) = ".pdf" Then ' Set location to pull file fromPDF

       

                      FileRnamePDF = ReadPathPDF & TestName

                  Else ' Select DWG file

                      FileRnamePDF = ReadPathDWG & TestName

                  End If

                  ' Transfer file over c:\print directories

                  Try

                      Dim file As IEdmFile5
                      Dim Folder As IEdmFolder5 = Nothing

                      file = vault.GetFileFromPath(FileRnamePDF, Folder)

                      'Folder = vault2.GetFolderFromPath(SavePathname)

                      If Strings.Right(FileRnamePDF, 4) = ".pdf" Then

                          If System.IO.File.Exists(FINsavepathPDF & TestName) Then
                              'File already exists and does not need to be copied

                          Else 'Copy file vault to C:\print\pdf location
                              Dim verEnum As IEdmEnumeratorVersion5
                              verEnum = file
                              Dim Version As Integer
                              Version = file.GetLocalVersionNo(Folder.ID)
                              Dim ver As IEdmVersion5
                              ver = verEnum.GetVersion(Version)
                             ver.GetFileCopy(Me.Handle.ToInt32(), FINsavepathPDF, 0)
               
                          End If

                      Else

                          If System.IO.File.Exists(FinsavepathDWG & TestName) Then
                              'File already exists and does not need to be copied

                          Else 'Copy file vault to C:\print\dwg location

                              Dim verEnum As IEdmEnumeratorVersion5
                              verEnum = file
                              Dim Version As Integer
                              Version = file.GetLocalVersionNo(Folder.ID)

                              Dim ver As IEdmVersion5
                              ver = verEnum.GetVersion(Version)
                              ver.GetFileCopy(Me.Handle.ToInt32(), FinsavepathDWG, 0)
                           End If

                      End If
                    
                  Catch ex As System.Runtime.InteropServices.COMException

                      If ex.ErrorCode.ToString("X") = "80040213" Then ' if file not found error

                          If (Strings.Right(TestName, 4) = ".pdf") Then
                              srPDF.WriteLine(TestName)
                          Else
                              srDWG.WriteLine(TestName)
                          End If

                      Else  ' other error - display

                          MessageBox.Show(FileRnamePDF & ": " & "HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)

                      End If

                  Catch ex As Exception
                      MessageBox.Show(ex.Message)
                  End Try

                  TestName = strrdr.ReadLine   ' Read next line

              Loop

              strrdr.Close()
              srPDF.Close()
              srDWG.Close()

              System.IO.File.Delete("C:\print\XFer.txt")

              'MsgBox("DONE")
              Label1.Text = "DONE"
              Button1.Show()

              'ExitApp()
          End Sub
          Public Sub ExitApp()

              Application.Exit()

          End Sub

          Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

          End Sub

          Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

              ExitApp()

          End Sub
      End Class

        • Re: Transfer list of files from epdm
          Chris Sonon

          Looking at your code it appears that you are doing LoginAuto, thus taking the logged in users permissions. Is it possible that your Materials user does not have permissions to obtain the file locally in the latest version?

           

          Logically if the code works on your machine and not on theirs the only variable in that instance is the user that is being logged in during the LoginAuto process. I would recommend replacing this with the standard Login and test with either your user or the Admin.