Community articleEncloseFile function
Added by IBM contributorIBM on July 26, 2013
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars


This function encloses a file in a form. The file must be accessible on the local computer. The IFormNodeP can refer to either a page node or an item node. If the IFormNodeP is a page node, the function creates a data item in that page to contain the enclosure. If the IFormNodeP is an item node, it must be a data item, and the function encloses the file in that node.
The file is enclosed using base64-gzip encoding.


   Function EncloseFile(
      theFile As String, 
      mimeType As String, 
      dataGroup As String, 
      identifier As String
      ) As IFormNodeP


Table 1. Function parameters
theFileStringThe path to the file on the local drive to enclose.
mimeTypeStringThe MIME type of the file. If null, the library will attempt to find a suitable MIME type for the file.
dataGroupStringThe data group to which this file should belong. If the object is a page node, you must provide this parameter. If the object is an item node, use null to keep the current datagroup option, or provide a different value to overwrite the option.
theIdentifierStringThe identifier to assign to the new data item if one is created. If null, either the current name is used or a unique name is automatically generated for the new data item.


The IFormNodeP of the item that contains the enclosure or throws an exception if an error occurs.


The following function encloses a file in a form. The function receives a form, uses DereferenceEx to locate the PAGE2 node in the form, and then uses EncloseFile to enclose a text file in the Notices datagroup. The file is stored in a data item named PersonnelNotice.
   Sub AttachFile(Form)
      Dim TempNode  ' object
      Set TempNode = Form
      ' Locate the PAGE2 node.
      Set TempNode = TempNode.DereferenceEx(vbNullString, "PAGE2", 0, _
         UFL_PAGE_REFERENCE, Nothing)
      ' Create an enclosure in this page.  The enclosure is stored in a data
      ' item called PersonnelNotice, is linked to the Notices datagroup, and
      ' encloses a text file from the local drive called Notice.txt.
      Set TempNode = TempNode.EncloseFile("c:\Notice.txt", "text/plain", _
         "Notices", "PersonnelNotice")
   End Sub

Parent topic:
FormNodeP functions