Skip to main content

Files & Documents

Commands that trigger file downloads or open document previews.


Download

Trigger a file download in the user's browser.

When to use: Downloading reports, documents, exports, or any generated file from the server.

JSON Response:

{
"feCommand": {
"Download": {
"outFileName": "Monthly_Report.pdf",
"filePath": "/path/to/file/report.pdf"
}
}
}
if (string.Equals(widgetName, "DOWNLOADBTN"))
{
string filePath = await GetFileFromStorage("report.pdf");

response.Set("FECommand", new Dictionary<string, object>
{
["Download"] = new
{
outFileName = "Monthly_Report.pdf",
filePath = filePath
}
});
}

// Stream the file if Download command is set
var feCommands = response.Get()["feCommand"] as Dictionary<string, object>;
if (feCommands != null && feCommands.ContainsKey("Download"))
{
var downloadData = feCommands["Download"] as dynamic;
string outFileName = downloadData.outFileName;
string filePath = downloadData.filePath;

if (System.IO.File.Exists(filePath))
{
S3FileStorageService s3 = (S3FileStorageService)_pluginServiceProvider.GetFileStorageProvider();
Response.ContentType = S3FileStorageService.GetMimeType(outFileName);
Response.Headers.Add("Content-Disposition", $"attachment; filename*=UTF-8''{Uri.EscapeDataString(outFileName)}");

using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
await s3.WriteFileInChunks(Response.Body, fs);
}

System.IO.File.Delete(filePath);
return new EmptyResult();
}
}

response.Set(HandlerResponse.FormData, request.FormData);
return Ok(await response.Get());

Parameters:

  • outFileName (string) - The filename shown to the user when downloading
  • filePath (string) - Server path to the file

PreviewDocument

Open a document preview modal.

When to use: Previewing PDFs, images, or other documents from file upload fields.

JSON Response:

{
"feCommand": {
"PreviewDocument": {
"context": null,
"fileId": "document-123.pdf",
"data": "JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL...",
"fieldName": "documentField",
"format": "pdf"
}
}
}
if (string.Equals(widgetName, "PREVIEWBTN"))
{
string fileId = "document-123.pdf";
string base64Data = GetBase64FileContent(fileId);

response.Set("FECommand", new Dictionary<string, object>
{
["PreviewDocument"] = new
{
context = (object)null,
fileId = fileId,
data = base64Data,
fieldName = "documentField",
format = "pdf"
}
});
}

response.Set(HandlerResponse.FormData, request.FormData);

Parameters:

  • context (object|null) - Optional context object
  • fileId (string) - File identifier
  • data (string|null) - Base64 encoded file content
  • fieldName (string) - Name of the field containing the file
  • format (string) - File format (default: "pdf")
info

Large files (.dwg, .ifc, .rvt, .rfa, .nwd, .nwc, .nwf) do not include base64 data — data is null for these types.