Creating file objects - SmartPlant Foundation - IM Update 44 - Customization & Programming - Hexagon

SmartPlant Foundation Customization

Language
English
Product
SmartPlant Foundation
Search by Category
Customization & Programming
SmartPlant Foundation / SDx Version
10

There is also a function for creating file objects, you pass in the fileinfo class, and it will work out the file type using the file extension. It then creates a file object, and it will populate all the properties and create the relationship to the file type.

Public Shared Function CreateFileObject(ByVal pobjSPFWindowsClient As SPFWindowsClient, ByVal pnodFileInfo As System.IO.FileInfo) As FileCreationResult

Public Shared Function CreateFileObject(ByVal pobjSPFWindowsClient As SPFWindowsClient, ByVal pstrClassDefinitionUID As String, ByVal pnodFileInfo As System.IO.FileInfo) As FileCreationResult

The example below is actual working code that will create a file object and call the server to work out what the vault is. Create the relationship between the file and vault and the file and its intended object. The variable lobjDocs is a container dictionary used to collect all the objects and relationships and sent to the server using the .Commit method.

Dim lobjFileInfo As New IO.FileInfo("c:\temp\Document1.doc")

Dim lobjFileResult As FileCreationResult = SPF.Client.Schema.Utilities.CreateFileObject(pobjWindowsFormsClient, lobjFileInfo)

lobjDocs.Add(lobjFileResult.File)

lobjDocs.Add(lobjFileResult.FileType.IObject)

lobjDocs.Add(lobjFileResult.RelFileFileType.IObject)

'

' You need to work out which vault the file is going to before you send it.

'

Dim lobjVault As IObject = Nothing

Dim lobjServerReq As New ServerRequest(pobjWindowsFormsClient.SPFSession, "GetVaultForNewFile")

lobjServerReq.AddQueryElement(lobjDocs.GetNode) ' It finds the object in this collection that has the ISPFFileComposition idef on it

lobjServerReq.Execute()

'

' Get the Vault from the reply

'

Dim lnodContainer As XmlNode = lobjServerReq.Response.SelectSingleNode("/Reply/Container")

Dim lobjContainer As IObjectDictionary = pobjWindowsFormsClient.SPFSession.InstantiateContainer(lnodContainer)

lobjVault = lobjContainer(0)

'

' Cast the file object so you can call the method on it

'

Dim lobjISPFFile As ISPFFile = CType(lobjFileResult.File.Interfaces("ISPFFile"), ISPFFile)

lobjISPFFile.UploadToLocalFileService(lobjVault)

'

' Create rel to the document object

'

Dim lobjIRel As IRel = SPF.Client.Schema.Utilities.CreateRel(pobjWindowsFormsClient.SPFSession, "SPFFileComposition", lobjISPFFile.IObject, lobjDocVersion)

lobjDocs.Add(lobjIRel.IObject)

'

' Add the file vault rel as well

'

Dim lobjFileVaultRel As IRel = SPF.Client.Schema.Utilities.CreateRel(pobjWindowsFormsClient.SPFSession, "SPFFileVault", lobjISPFFile.IObject, lobjVault)

lobjDocs.Add(lobjFileVaultRel.IObject)