Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

File Associations at AddFile

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
dominiekvanwest
715 Views, 4 Replies

File Associations at AddFile

Hi,

I want to add a file to the Vault that has an attachment. So I first add the attachment and then I want to add the file with an association to the attachment. I use the following code:

 

WebServicesByteArray.Bytes = System.IO.File.ReadAllBytes(LibrarymapLocal & "Test.ipt.dwf")

serviceManager.DocumentService.AddFile(folder.Id, Test.ipt.dwf", "", System.IO.File.GetLastWriteTime(LibrarymapLocal & "Test.ipt.dwf"), Nothing, Nothing, DocumentService.FileClassification.None, True, WebServicesByteArray)

WebServicesByteArray.Bytes = System.IO.File.ReadAllBytes(LibrarymapLocal & "Test.ipt")

Dim Association(0) As Autodesk.Connectivity.WebServices.FileAssocParam

Association(0).CldFileId = fileId

Association(0).ExpectedVaultPath = Librarymap

Association(0).Typ = AssociationType.Attachment

serviceManager.DocumentService.AddFile(folder.Id, "Test.ipt", "", System.IO.File.GetLastWriteTime(LibrarymapLocal & "Test.ipt"), Association, Nothing, DocumentService.FileClassification.None, False, WebServicesByteArray)

But I get an error (System.NullReferenceException) at: Association(0).CldFileId=fileId

What am I doing wrong? What's the correct way to add a file with an attachment? (The (0) is there because it has to be an array)

 

Thanks in advance!

 

Dominiek

4 REPLIES 4
Message 2 of 5
Redmond.D
in reply to: dominiekvanwest

You declared the array, but you need to create a new object to fill it.  Try adding the following line:

 

Association(0) = new Autodesk.Connectivity.WebServices.FileAssocParam()



Doug Redmond
Software Engineer
Autodesk, Inc.

Message 3 of 5
dominiekvanwest
in reply to: Redmond.D

Thank you for your quick reply.

This does it!

Just wondering, if the array contains more than 1 element, I'll need to do this for every item in the array? So something like this:

For i as Integer = 0 to Association.Length - 1

     Association(0) = new Autodesk.Connectivity.WebServices.FileAssocParam()

Next i

Message 4 of 5
Redmond.D
in reply to: dominiekvanwest

Correct.  Except your would use Association(i) inside the loop, not Association(0)



Doug Redmond
Software Engineer
Autodesk, Inc.

Message 5 of 5
dominiekvanwest
in reply to: Redmond.D

Oh, yeah, off course with i instead of 0. Just typed it in here without checking 🙂

 

Thank you very much for the help!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report