How do I set my WorkflowFileUpload control as a required field?

Issue

I cannot set my WorkflowFileUpload control to be a required field using the FORM_FIELDS_REQUIRED action parameter.

Solution

The WorkflowFileUpload control is not supported by the FORM_FIELDS_REQUIRED parameter. However, you can validate your WorkflowFileUpload by checking the .HasFile property before you call the SubmitToWorkflow() method.

You can also create a client-side custom validation to check if a file has been uploaded to the WorkflowFileUpload control.

Example

Assuming you have a WorkflowFileUpload control with the ID UPLOAD1, add a .NET CustomValidator with a ClientValidationFunction that validates UPLOAD1 (see How can I use a .NET CustomValidator control in my WorkflowGen web form?).

In the .aspx file, bind this JavaScript function to ClientValidationFunction of the CustomValidator.

function ValidateWFGFileUpload(source, arguments)
{
 var ValidateResult = true;
 ValidateResult = CheckUPLOAD();
 arguments.IsValid = ValidateResult;
}

In the .cs file, add the following under Page_PreRender():

string WFGFileUploadStatus = UPLOAD1.HasFile.ToString().ToLower();
ClientScript.RegisterClientScriptBlock(typeof(string), "ValidateWFGFileUpload", "function CheckUPLOAD() {return " + WFGFileUploadStatus + "; }", true);

Whenever a user uploads a file through WorkflowFileUpload, the .HasFile property will be set to True. You can use the above client script to define the validation result. If you have multiple WorkflowFileUpload controls to be validated, you can combine your FileUpload status and set it to the client-side script return value.