Trying to use AddFile

Trying to use AddFile

larry.daubenspeck
Advocate Advocate
693 Views
4 Replies
Message 1 of 5

Trying to use AddFile

larry.daubenspeck
Advocate
Advocate

I am simply trying to add a file to my vault using the AddFile method, but for the life of me, can't get it to work.  All the samples use variable names, or FolderIds, but I need to see actual strings to know what's going on.  So many questions; so few answers...

 

FolderId

  • What is a folder id?
  • How do I get it if all I know is its name?

Parent folder

  • What is this supposed to represent?
  • Is this on my hard drive, or in the vault? 
  • What if it doesn't exist yet? 
  • Will it get created automatically?

DocumentService.GetFolderByPath method

  • Is there a secret to its syntax? 
  • Backslashes? 
  • Forward slashes? 
  • Double slashes?
  • It won't even find "$" for me.

A comprehensive explanation would be great!

 

Thanks!

Larry Daubenspeck
Software Programmer
Draper, Inc.
0 Likes
Accepted solutions (1)
694 Views
4 Replies
Replies (4)
Message 2 of 5

gavbath
Collaborator
Collaborator

Barry, post up a code sample that looks useful to what you are trying to do, and I will try and talk you through it and explain it.

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

0 Likes
Message 3 of 5

larry.daubenspeck
Advocate
Advocate

Thanks Gavin, here is my function...

   

Friend Function CheckInFile(FilePath As String, FileName As String, ByRef ErrorMsg As String) As Boolean

 

        'Login result (Username and password are ignored for WinAuth connections).
        Dim authFlag As VDF.Vault.Currency.Connections.AuthenticationFlags = VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication
        Dim LoginResult As VDF.Vault.Results.LogInResult = VDF.Vault.Library.ConnectionManager.LogIn(ServerName, VaultName, vbNull, vbNull, authFlag, Nothing)

 

        If Not LoginResult.Success Then
            ErrorMsg = "Unsuccessful Login to Vault."
            Return False
            Exit Function
        End If

 

        'Connection.
        Dim connection As VDF.Vault.Currency.Connections.Connection = LoginResult.Connection

 

        'Document Service
        Dim DocServ As ACW.DocumentService = New ACW.DocumentService

 

        'Paths.
        Dim LocalPath As String = "C:\Vault Workspace\Project\Gym Equipment CAD\Orders\"
        Dim VaultPath As String = LocalPath.Replace("C:\Vault Workspace\", "$\")

 

        'Do I need to do this?
        'Replace the backslashes with forward slashes.
        VaultPath = VaultPath.Replace("\", "/")

 

        Dim aFolder As ACW.Folder = Nothing
        Try
            'This is the line which errors...
            aFolder = DocServ.GetFolderByPath(VaultPath)
        Catch ex As Exception
            ErrorMsg = "Error with the GetFolderByPath() method.  The path is:  " & VaultPath & "." & vbCrLf & vbCrLf & ex.ToString
            Return False
            Exit Function
        End Try

 

        Dim ParentFolder As VDF.Vault.Currency.Entities.Folder = New VDF.Vault.Currency.Entities.Folder(connection, aFolder) ' New Autodesk.Connectivity.WebServices.Folder)

 

        Try
            Using stream As New FileStream(FilePath & FileName, FileMode.Open, FileAccess.Read)
                connection.FileManager.AddFile(ParentFolder, FilePath & FileName, "Added by automation.", DateTime.Now, Nothing, Nothing, ACW.FileClassification.None, False, stream)
            End Using
        Catch ex As Exception
            ErrorMsg = "Error trying to check in " & FileName & " to vault." & vbCrLf & vbCrLf & ex.ToString
            Return False
            Exit Function
        End Try

 

        Return True

 

    End Function

 

Here is the error I'm getting...

System.Net.WebException: The request failed with HTTP status 404: Not Found.

 

Thanks again!

Larry Daubenspeck
Software Programmer
Draper, Inc.
0 Likes
Message 4 of 5

gavbath
Collaborator
Collaborator
Accepted solution

I think the issue is how you're accessing the DocumentService

 

The connection object has the DocumentService now so get it like this:

 

'Document Service
        Dim DocServ As ACW.DocumentService = connection.WebServiceManager.DocumentService

 

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

Message 5 of 5

larry.daubenspeck
Advocate
Advocate

Gavin,

 

Yes, I finally saw that late yesterday (after only a couple of days, I read something on CoolOrange's website about it.).  You have confirmed it...thanks again!

Larry Daubenspeck
Software Programmer
Draper, Inc.
0 Likes