Community articleencloseFile method
Added by IBM contributorIBM on August 15, 2011
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.


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


   public FormNodeP encloseFile(
      String theFile,
      String mimeType,
      String dataGroup,
      String identifier
      ) throws UWIException;


Table 1. Method 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 FormNodeP of the item that contains the enclosure or throws a generic exception (UWIException) if an error occurs.


The following example demonstrates how to use encloseFile to enclose a graphics file in a form. First, dereferenceEx is used to locate the node for the first page. Then, depending on the gender, encloseFile is called to enclose one of two possible image files. Because the subject node is a page node, encloseFile creates a new data node in which to store the image file.
   private static void enclosePic(String theGender) throws Exception
      FormNodeP tempNode;
      if ((tempNode = theForm.dereferenceEx(null, "PAGE1", 0,
         FormNodeP.UFL_PAGE_REFERENCE, null)) == null)
         throw new Exception("Could not find PAGE1.");
/* The following logic detemines whether the gender is "male" or "female". */
      if (theGender.equals("male"))
         if ((tempNode = tempNode.encloseFile("male.jpg", "image/jpeg",
            null, "PICDATA")) == null)
            throw new Exception("Could not enclose image file.");
   /* This call to encloseFile is similar to the previous one. The only
      difference is that it specifies a different image. */
         if ((tempNode = tempNode.encloseFile("female.jpg", "image/jpeg", 
            null, "PICDATA")) == null)
            throw new Exception("Could not enclose image file.");

Parent topic:
FormNodeP class