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
Solved! Go to Solution.
Solved by Redmond.D. Go to Solution.
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()
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
Correct. Except your would use Association(i) inside the loop, not Association(0)
Oh, yeah, off course with i instead of 0. Just typed it in here without checking 🙂
Thank you very much for the help!