Back to Devexpress

Attach Files to Objects

expressappframework-403288-getting-started-in-depth-tutorial-blazor-enable-additional-modules-attach-files-to-objects.md

latest3.1 KB
Original Source

Attach Files to Objects

  • Oct 01, 2025
  • 4 minutes to read

This lesson describes how to attach file collections to objects.

In this lesson you will do the following:

  • Add the File Attachment Module to the application.
  • Implement new entity classes: Resume to store a Contact’s resume information and PortfolioFileData to save file data collection items.

Note

Before you proceed, take a moment to review the previous lessons:

Step-by-Step Instructions

  1. Add the DevExpress.ExpressApp.FileAttachment.Blazor NuGet package to the MySolution.Blazor.Server project and the DevExpress.ExpressApp.FileAttachment.Win NuGet package to the MySolution.Win project. See the following topic for more information on how to install DevExpress NuGet packages: Choose Between Offline and Online DevExpress NuGet Feeds.

  2. In the MySolution.Blazor.Server project, open the Startup.cs file and add the File Attachment module to the application builder. Do the same in the Startup.cs file of the MySolution.Win project:

  3. In the MySolution.Module\Business Objects folder, create the Resume class. Replace the generated class declaration with the following code:

  4. Add the Resume property to the Employee class:

  5. Create the PortfolioFileData class. Replace the generated class declaration with the following code:

  6. Add the Required attribute to the Resume property in the PortfolioFileData class.

  7. Open the MySolution.Module.BusinessObjects\MySolutionDbContext.cs file and add the properties of Resume and PortfolioFileData types to DbContext:

  8. Run the application. Open the Resume List View and create a new Resume object. Fill the Employee field and add a new Portfolio File Data object. In the Portfolio File Data window, select the file that you wish to attach.

Users can click the file link to download the resume file.

To get a file stored within a PortfolioFileData object in code, use the SaveToStream(Stream) method of its File property.

Next Lesson

Create and Preview a Report