How can I add a file to a process data without using a FileUpload control within an EFORMASPX form?

You can add a file to a process data without using any FileUpload controls within an EFORMASPX form.

WorkflowGen.My will look for a file uploaded by the FileUpload control at submission. If you want to dynamically add a file to a WorkflowGen process data without prompting the user to upload a file, you need to make sure that WorkflowGen.My is still prepared to receive a file as an OUT parameter even if there is no FileUpload control in the form.

Solution

A standard file upload in WorkflowGen requires two pieces of information: a physical file to be uploaded to the action’s temporary storage path, and a parameter name registered as a valid data field in the form data file.

To do this without the help of a FileUpload control, do the following:

  1. Prepare the source file by copying it to the WorkflowGen action temporary storage path.

  2. Create an invisible .NET Label control on the form as a file placeholder for WorkflowGen’s form data.

  3. Set the label’s text as the file path of the uploaded file.

Example

//----- a label control with ID = "UPLOAD1" is added on aspx page

String SourceFolder = "C:\\Inetpub\\wwwroot\\wfgen\\WfApps\\MyProject";
String TargetFolder = "upload\\" + UPLOAD1.ID;
String FileName = "test.txt";

// --- prepare folder for temporary storage of the upload file
// --- StoragePath is a predefined string variable inherited from WorkflowGen
// --- containing the storage path for files of the current form action

DirectoryInfo di = new DirectoryInfo(StoragePath + "\\" + TargetFolder);
if (!di.Exists)
{ di.Create(); }


FileInfo fi = new FileInfo(SourceFolder + "\\" + FileName);
fi.CopyTo(StoragePath + "\\" + TargetFolder + "\\" + FileName);

UPLOAD1.Text = TargetFolder + "\\" + FileName;