show / hide menu

Download File

The DownloadFile function is used to download a file from a specified file upload control, with an optional parameter to specify the file index if multiple files are uploaded.

Function Definition:

DownloadFile(Control name, FileIndex)


Parameters:

  • Control name (Control): This parameter specifies the name of the file upload control from which you wish to download the file. It must match the control name as defined in your application. This is a required parameter.
  • FileIndex (Optional): his parameter specifies the index of the file to download from the file upload control. The index helps identify which file to download when multiple files are uploaded. If omitted, the function defaults to downloading the first file. The starting index is 0 and this is an optional parameter.

Example with Optional Argument

  • DownloadFile(FileUpload1, 1)


In this example, the function downloads the file at index 1 from the file upload control named FileUpload1. The FileIndex is provided, indicating which specific file to download if there are multiple files uploaded.

Figure1: Rule

Figure2: Designer

Figure 3: Preview (On clicking the “DownloadFile” button, print.pdf is downloaded)

Example without Optional Argument

  • DownloadFile(FileUpload1)


In this example, the function downloads the file from the file upload control named FileUpload1 without specifying an index. This implies that the function will download the first file or the default file if only one file is present.

Figure4: rule

Figure 3: Preview (On clicking the “DownloadFile” button, Capture1.PNG is downloaded)

Practical Use

  • With FileIndex: Use this when you need to download a specific file from a list of multiple files that have been uploaded. For example, if a user uploads several documents and you want to download the second document, you need to specify the index as 1.
  • Without FileIndex: Use this when there is only one file in the upload control or when you want to download the first file by default.

Summary

The DownloadFile function is a flexible way to handle file downloads from a file upload control within an application. By specifying the control name and optionally the file index, it allows for precise control over which file to download, making it useful for applications that involve file uploads and need to handle multiple files efficiently.