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


#1

Issue

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

Background

You need to set the FileUpload control as IN/OUT parameter in the WorkflowGen action so that the uploaded file can be imported exported between the webform 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 call of SubmitToWorkflow() at submission of your webform

For example,

  1. Create a FileUpload control with the ID “FileUpload1”:
<asp:FileUpload ID=FIleUpload1" runat="server" />
  1. 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" />
  1. In your code behind, clear FileUpload1 after the callto 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. The WorkflowGenFileUpload 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, you have a WorkflowGenFileUpload with an ID “WFGFileUpload1”. In your code behind, add:

WFGFileUpload1.UpdateText = "";

Once a file is uploaded, the update link will not appear. Take a look at the before and after:

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


WorkflowFileUpload object- press "Delete" from code behind?