Accessing form attachment in code

I'm trying to access an uploaded bizform file that was uploaded using the FileUploaderComponent upon form submission. The API documentation I linked below is less than helpful.

I can get the form submission column data but I'm unable to retrieve the submitted file. My simplified code is shown below:

var path = "/assets/bizformfiles/" + file.SystemFileName;
var fileBytes = CMS.IO.File.ReadAllBytes(path);
var ms = new MemoryStream(fileBytes)
{
    Position = 0
};
emailMessage.Attachments.Add(new(ms, file.OriginalFileName));

Environment

Tags:
Form Builder SaaS v31.5.0 ASP.NET Core

Answers

I haven't tried this myself, but there are two types used to manage files of Form Builder file component uploads.

  • CMS.OnlineForms.IBizFormFilePathProvider - Provides physical folder paths for BizForm files and temporary files.

  • CMS.OnlineForms.IBizFormFileService - Defines manipulation methods for a file uploaded via forms.

You want IBizFormFilePathProvider to get the non-temp path files are stored in. Then you can use your File.ReadAllBytes() approach or CMS.IO.StorageHelper.GetFile(path) if you need more metadata.

The BizFormFilePathProvider keeps the files path abstracted away in case you use custom storage path mapping to move things around or use cloud storage.

To response this discussion, you have to login first.