How can I delete a file attachment instead of adding/updating it using the standard .NET FileUpload control?

Issue

How can I delete a file attachment instead of adding/updating it using the standard .NET FileUpload control?

Background

To do this, you need to set the FileUpload control as IN/OUT parameter in the WorkflowGen action so that the uploaded file can be imported and exported between the web form and WorkflowGen process data.

When using the .NET FileUpload Control, a user can only browse and upload a file to WorkflowGen upon submission. This allows the user to update the file, but not to delete an existing file. If you do not upload a new file, WorkflowGen just keeps the existing file without updating the associated process data.

Solution

To allow a user to add or remove a file using the standard .NET FileUpload control:

  1. Add your own trigger to mark your FileUpload as deleted.

  2. Clear your FileUpload in FormData after the SubmitToWorkflow() call at submission of your web form.

Example

  1. Create a FileUpload control with the ID FileUpload1:

    <asp:FileUpload ID=FIleUpload1" runat="server" />
    
  2. Add a button to delete any existing file in FileUpload1 inherited from the previous action:

    <asp:Button ID="Delete_FileUpload1" runat="server" OnClick="Delete_FileUpload1_Click" Text="Delete FileUpload1" />
    
  3. In your code-behind, clear FileUpload1 after the cal lto SubmitToWorkflow():

    protected void Delete_FileUpload1_Click(object sender, EventArgs e)
     {
     SubmitToWorkflow();
     FormData.Tables["Table1"].Rows[0]["FileUpload1"] = "DELETE";
      SaveFormData(FormData);
     }
    

Another approach is to use the WorkflowGenFileUpload control, which has a built-in delete function. Unfortunately, there is no attribute to only disable the modify option, but you can hide the delete option by clearing the UpdateText.

For example, if you have a WorkflowGenFileUpload with the ID WFGFileUpload1, you would add the following to your code-behind:

WFGFileUpload1.UpdateText = "";

Once a file is uploaded, the update link will not appear. Here’s the before and after:

xxxxxx.txt (4 Bytes) [| Delete] instead of xxxxxx.txt (4 Bytes) [Update | Delete]