Skip to main content
A newer version of this page is available. .

How to: Implement File Data Properties

  • 4 minutes to read

This topic demonstrates how to implement a business class with a file data property and a file collection property. For this purpose, the Resume class, which is used to store and manage an employee’s resume information, is implemented. It has three properties: File, Contact and Portfolio. The File property provides a file, the Contact property contains a reference to the Contact class, and the Portfolio property returns a collection of the employee’s files.

To add a file data type property and a file collection property to a business object, you should use a type that implements the IFileData interface and one that applies the FileAttachment attribute. In this instance, the FileAttachmentsWindowsFormsModule, FileAttachmentsAspNetModule and/or FileAttachmentMobileModule modules should be added to your WinForms, ASP.NET Web and/or Mobile module projects respectively. These modules contain Property Editors for IFileData type properties, and Controllers with Actions that are necessary for file manipulation. Note that the Mobile Property Editor for a IFileData property supports only the file download. For details, refer to the File Attachments Module Overview topic.

To add the FileAttachmentsWindowsFormsModule, FileAttachmentsAspNetModule and (or) FileAttachmentMobileModule module(s) to the application, invoke the Module Designer for the WinForms, ASP.NET and (or) Mobile module project(s), drag the corresponding item from the Toolbox to the Designer’s Required Modules section, and rebuild the solution.

The following code demonstrates a Resume business object.

[DefaultClassOptions]
public class Resume : BaseObject {
   public Resume(Session session) : base(session) {}
   private Contact contact;
   private FileData file;
   [Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never)]
   public FileData File {
      get { return file; }
      set {
         SetPropertyValue("File", ref file, value);
      }
   }
   public Contact Contact {
      get { 
         return contact;
      }
      set {
         SetPropertyValue("Contact", ref contact, value);
      }
   }
  [Aggregated, Association("Resume-PortfolioFileData")]
  public XPCollection<PortfolioFileData> Portfolio {
     get { return GetCollection<PortfolioFileData>("Portfolio"); }
  }
}
public class PortfolioFileData : FileAttachmentBase {
   public PortfolioFileData(Session session) : base(session) {}
   private DocumentType documentType;
   protected Resume resume;
   [Persistent, Association("Resume-PortfolioFileData")]
   public Resume Resume {
      get { return resume; }
      set { 
         SetPropertyValue("Resume", ref resume, value); 
      }
   }
   public override void AfterConstruction() {
      base.AfterConstruction();
      documentType = DocumentType.Unknown;
   }
   public DocumentType DocumentType {
      get { return documentType; }
      set { SetPropertyValue("DocumentType", ref documentType, value);}
   }
}
public enum DocumentType { SourceCode = 1, Tests = 2, Documentation = 3, 
   Diagrams = 4, ScreenShots = 5, Unknown = 6 };

To create a collection of an employee’s files, the Resume class has the Portfolio property of the XPCollection<PortfolioFileData> type. The PortfolioFileData class is inherited from the FileAttachmentBase class, which in turn, uses the FileAttachment interface. The FileAttachmentBase class, as well as the FileAttachment attribute, is from the Business Objects Library.

The PortfolioFileData class has the DocumentType property that specifies the portfolio file type. This property is initialized in the AfterConstruction method override. The PortfolioFileData class also stores a reference to a Resume object in its Resume property.

The following images show the Resume Detail View in WinForms, ASP.NET Web and Mobile applications.

ResumeInWin

ResumeInWeb

ResumeInMobile

See Also