How to attach or remove a file to a WorkflowFileUpload control in code-behind

Requirements

  • WorkflowGen v6.1.4 and later
  • WorkflowFileUpload v3.0.5 and later

Procedure

  1. In the form designer, add an attachment tool to your form with the Enable advanced mode option checked, or add a new WorkflowFileUpload control to your custom web form in Visual Studio.
  2. Rename the control ID (e.g. REQUEST_FILE1).
  3. Add a parameter to the action that returns the file attachment from REQUEST_FILE1 to a process data (e.g. REQUEST_FILE1 : OUT : DATA_FILE1).
  4. In an asp:Button control’s Click event or a form’s Page_Load event, add a call to the WorkflowFileUpload’s AttachFile() method, which adds a file to the control, or a call to the RemoveFile() method, which removes a file from the control. The file must be locally accessible to the web server hosting the web form.

Example for attaching a file

protected void BUTTON_ATTACH_FILE_Click(object sender, EventArgs e) {
    REQUEST_FILE1.AttachFile("\\ServerComputerName\ShareName\file.txt");
}

Example for removing a file

protected void BUTTON_REMOVE_FILE_Click(object sender, EventArgs e) {
    REQUEST_FILE1.RemoveFile();
}