Copy Code
|
|
---|---|
Private Function BuildComponentsTree() As Component ' Create a components folder and add a component ' Create a components folder named myComponentsFolder under the root folder, ' then find this folder by it's path, and add a component, myComponent to it. ' Return myComponent. Dim generalComponentFolderFactory, rootComponentFolderFactory As ComponentFolderFactory Dim cFolder, rootCFolder As ComponentFolder Dim compFactory As ComponentFactory Dim myComp As Component ' Get a general ComponentFolderFactory from the TDConnection object Set generalComponentFolderFactory = tdc.ComponentFolderFactory ' Get the root folder Set rootCFolder = generalComponentFolderFactory.Root ' Get a folders factory Set rootComponentFolderFactory = rootCFolder.ComponentFolderFactory ' Add myComponentsFolder under root Set cFolder = rootComponentFolderFactory.AddItem(Null) cFolder.name = "myComponentsFolder" ' Post to Server cFolder.Post ' Finding my new folder, by it's path Set cFolder = generalComponentFolderFactory.FolderByPath("Components\myComponentsFolder2") ' Get a ComponentFactory Set compFactory = cFolder.ComponentFactory ' Add the component Set myComp = compFactory.AddItem(Null) Dim errString As String If (compFactory.IsComponentNameValid("myComponent", errString)) Then myComp.name = "myComponent1" Else myComp.name = "DefaultValidName" End If ' Using the parent folder to store it's ID in the newly created Component ' NOTICE ! this field is not initialized on it's own. You must do it yourself. myComp.Field("CO_FOLDER_ID") = cFolder.ID myComp.Post Set BuildComponentsTree = myComp End Function |